5ervant

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

11 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

No one can guess?
So that means, such kind of dynamic button can't be click using IE.au3 or FF.au3 ..  :'(

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
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..

Share this post


Link to post
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.

Share this post


Link to post
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

 

Share this post


Link to post
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() .

Share this post


Link to post
Share on other sites

You need to change the _FFXPath command to grab the desired element. How would you change this line

_FFXPath( "//div[@class='open-menu']")

so that it grabs the 2nd instance of a matching div?

Share this post


Link to post
Share on other sites
(//div[@class='open-menu'])[2]

A hour spent..

1 person likes this

Share this post


Link to post
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

  • Similar Content

    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • Dent
      By Dent
      As the title says. I open IE11 and navigate to a page with the following HTML5 file upload container in Capture0.JPG
      I want to click Add Files but I haven't been able to. Here's the code that handles the Add Files button in Capture.JPG
      _IEGetObjectById and then using _IEAction to click it doesn't work. I can't give access to the actual page unfortunately because it's password protected.
      All suggestions welcome.


    • dadalt95
      By dadalt95
      Perform a simple google search!
      The script below works fine until fill the google form!
      What I can't find is how to submit the form, tried a couple of ways and none of them worked.

       
      #include <IE.au3> $oIE = _IECreate ("www.google.com") $o_form = _IEFormGetObjByName ($oIE, "f") $o_login = _IEFormElementGetObjByName ($o_form, "q") $username = "80251369" _IEFormElementSetValue ($o_login, $username) $o_numer = _IEGetObjByName($o_form, "btnK") _IEAction ($o_numer, "click")  
      The code runs without any problem.
      I don't know how to proceed!
      Thanks in advance!
    • milos83
      By milos83
      I have one script that creates _IECreateEmbedded and another script that does _IEAttach.
      I do this because when autoit is doing something, the Embedded IE starts stalling (eg jquery progress animation)
      But there is a new problem.
      When IE is having its own process (like in the example above) any _IE command is slow (in the script that Attaches).
      Here is a comparison of when its in separate and when its in same process:
      Separate process _IETagNameGetCollection : 5000ms
      Separate process _IEAction: 850ms
      Same process _IETagNameGetCollection : 1ms
      Same proccess _IEAction: 135ms
       
      If I try to attach to an embedded IE that is done in c#, I get lightning fast results.
      As you can see, _IE functions work very slow when the embedded IE we are attaching to is made in Autoit.
       
      I did a test and if I empty the WHILE loop in IE process I get these results(but the cpu is at 30% as expected):
      Separate process _IETagNameGetCollection : 33ms
      Separate process _IEAction: 13ms
       
      It slows down if you put anything (like GUIGetMsg) in the WHILE loop.
       
      How do I fix this?
       
      Create IE:
      #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Local $oIE = _IECreateEmbedded() GUICreate("My Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.autoitscript.com") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ;takes 1ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ;takes 135ms ConsoleWrite(TimerDiff($timer) & @CRLF) While 1 Local $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd  
      Attach to IE:
      #include <IE.au3> Local $oIE = _IEAttach("My Embedded Web control Test", "embedded") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ; 5000ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ; 850ms ConsoleWrite(TimerDiff($timer) & @CRLF)  
       
      attach.au3
      create.au3