Jump to content

Clicking on a selected button causing its container element to be click


Recommended Posts

Go create a quick account in Zapier and go to https://zapier.com/app/dashboard and make some Zaps!
Just need to click the specific instance of an .open-menu button and then click its a.run (anchor) element.
Doing this IE.au3 script just causing to click its container element:

$target = 1; Target the first instance


#include <IE.au3>
$oIE = _IEAttach("Dashboard - Zapier")

$count = 0;
$tags = _IETagNameGetCollection($oIE, "div")
For $tag in $tags
    $class_value = $tag.GetAttribute("class")
    If $class_value = "open-menu" Then
        $count += 1
        
        if $count = $target Then
            MsgBox(0, "Instance: ", $count)
;           $tag.fireEvent("onmousedown")
;           _IEAction($tag, "click")
;           $tag.fireEvent("onmouseup")

;           Or this but not working
;           $tag.Click
        EndIf
    EndIf
Next

I also tried to do it using FF.au3

$target = 1; Target the first instance


#Include <Array.au3>
#Include <FF.au3>

$count = 0;
If _FFConnect(Default, Default, 3000) Then
    $aArray = _FFXPath( "//div[@class='open-menu']", "", 7 )
;   _ArrayDisplay($aArray)

    For $tag in $aArray
        $count += 1

        if $count = $target Then
            MsgBox(0, "Instance: ", $count)
            _FFClick($tag)
        EndIf
    Next
EndIf

Error: _FFClick ==> No match: $sElement: [number]

Could some help me how to click such buttons on such kind of a dynamic page?

Edited by 5ervant
Link to comment
Share on other sites

You have to examine the underlying event code to be able to figure out how to trigger the menu. In this case, there's a single event on the main container that is used for each of the objects within that container. The event looks at the position of the click to determine which element to actually trigger.

Here's some code that will cause the menu to appear --

#Include <FF.au3>

If _FFConnect(Default, Default, 3000) Then
    _FFXPath( "//div[@class='open-menu']")

    If @error = $_FF_ERROR_Success Then
        $pos = _FFCmd('FFau3.xpath.getBoundingClientRect().x') + 1
        $cmd = "d=FFau3.WCD.createEvent('MouseEvent');d.initMouseEvent('click',true,true,window,0,0,0," & $pos & ",0,0,0,0,0,0,null);FFau3.xpath.parentNode.parentNode.parentNode.dispatchEvent(d);"
        _FFCmd($cmd)
    EndIf
EndIf

It creates a click event with the proper positioning value and then passes it to the container element to be processed.

Link to comment
Share on other sites

7 hours ago, Danp2 said:

You have to examine the underlying event code to be able to figure out how to trigger the menu. In this case, there's a single event on the main container that is used for each of the objects within that container. The event looks at the position of the click to determine which element to actually trigger.

Here's some code that will cause the menu to appear --

#Include <FF.au3>

If _FFConnect(Default, Default, 3000) Then
    _FFXPath( "//div[@class='open-menu']")

    If @error = $_FF_ERROR_Success Then
        $pos = _FFCmd('FFau3.xpath.getBoundingClientRect().x') + 1
        $cmd = "d=FFau3.WCD.createEvent('MouseEvent');d.initMouseEvent('click',true,true,window,0,0,0," & $pos & ",0,0,0,0,0,0,null);FFau3.xpath.parentNode.parentNode.parentNode.dispatchEvent(d);"
        _FFCmd($cmd)
    EndIf
EndIf

It creates a click event with the proper positioning value and then passes it to the container element to be processed.

Thanks, it would be great if you can show a IE.au3 version of that 'cause that FF.au3 version is hard to understand, just for educational purpose..

Link to comment
Share on other sites

2 hours ago, 5ervant said:

Thanks, it would be great if you can show a IE.au3 version of that 'cause that FF.au3 version is hard to understand, just for educational purpose..

Sorry, but your on your own there. :-)

Suggest that you search to forum for a solution. IIRC, there's a post by DaleHolm that addresses a similar issue.

Link to comment
Share on other sites

Could try:

#RequireAdmin
#include <IE.au3>

$oIE = _IECreate("https://zapier.com/app/dashboard", 1)
$oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv in $oDivs
    If $oDiv.ClassName = "open-menu" Then
        $hWnd = _IEPropertyGet($oIE, "hWnd")
        ControlClick($hWnd, "", "", "left", 1, _IEPropertyGet($oDiv, "browserx") + 2, _IEPropertyGet($oDiv, "browsery") + 2)
        ExitLoop
    EndIf
Next

 

Link to comment
Share on other sites

On 5/5/2017 at 8:34 AM, Danp2 said:

You have to examine the underlying event code to be able to figure out how to trigger the menu. In this case, there's a single event on the main container that is used for each of the objects within that container. The event looks at the position of the click to determine which element to actually trigger.

Here's some code that will cause the menu to appear --

#Include <FF.au3>

If _FFConnect(Default, Default, 3000) Then
    _FFXPath( "//div[@class='open-menu']")

    If @error = $_FF_ERROR_Success Then
        $pos = _FFCmd('FFau3.xpath.getBoundingClientRect().x') + 1
        $cmd = "d=FFau3.WCD.createEvent('MouseEvent');d.initMouseEvent('click',true,true,window,0,0,0," & $pos & ",0,0,0,0,0,0,null);FFau3.xpath.parentNode.parentNode.parentNode.dispatchEvent(d);"
        _FFCmd($cmd)
    EndIf
EndIf

It creates a click event with the proper positioning value and then passes it to the container element to be processed.

Can you give me another twick of that, that will click let say, the second button?

'Cause @Subz solution isn't that nice, will require you to activate the window before working..
And upon a quick testing, no @DaleHohm solution work and still, a ControlClick() .

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...