Pedro de Sá
Pedro de Sá

Reputation: 780

VBA click at element in IE

I can't click on an element in the screen, it's not a button but works like one. I have successfully located it through the web inspector (I think) but I can't figure out the reason of why isn't working... Previously in my code I used the same code for clicking in a "Log in" button and it worked perfectly. Here it is the code:

    Set objCollection = IE.document.getelementsbytagname("div")
    For Each elem In objCollection
        If IsObject(IE.document.getElementsByClassName("btn-group")) Then 'Scratchpad button clicking
            If IsObject(IE.document.getElementsByClassName("pull-left fang-button fang-button-subtle no-margin ng-binding")) Then
                Debug.Print "found it"
                elem.Click
                Exit For
            End If
        End If
    Next elem

I'm trying to click in the element "Scratchpad" at the top of the page, as the image shows. Thanks in advance!

HTML:

<div class="btn-group" role="group" style="border:1px solid #ccc"> <a ng-class="{'active': !CrossSegmentConfig.showScratchPad &amp;&amp; !CrossSegmentConfig.showGraph}" class="pull-left fang-button fang-button-subtle no-margin ng-binding active" ng-click="CrossSegmentConfig.showScratchPad=false; CrossSegmentConfig.showGraph=false;" style=""> <i class="fa fa-align-left"></i> Parameters </a> <a ng-class="{'active': CrossSegmentConfig.showScratchPad}" class="pull-left fang-button fang-button-subtle no-margin ng-binding" ng-click="CrossSegmentConfig.toggleScratchPad()" style=""> <i class="fa fa fa-columns"></i> Scratchpad </a> <a ng-class="{'active': CrossSegmentConfig.showGraph}" class="pull-left fang-button fang-button-subtle no-margin ng-binding" ng-click="CrossSegmentConfig.toggleGraph()"> <i class="fa fa-line-chart"></i> Plot </a> </div>

Upvotes: 2

Views: 666

Answers (1)

QHarr
QHarr

Reputation: 84455

It's an Angular JS directive. Try either of the following 2

ie.document.querySelector("[ng-click*=toggleScratchPad]").click

ie.document.parentWindow.execScript "document.querySelector('[ng-click*=toggleScratchPad]').click();"

Upvotes: 1

Related Questions