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



#2 ·  Posted

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

#3 ·  Posted

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

#4 ·  Posted

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

#5 ·  Posted

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

#6 ·  Posted

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

#7 ·  Posted

This is the original thread I was referring to, which uses a solution similar to @Subz.

Share this post


Link to post
Share on other sites

#8 ·  Posted

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

#9 ·  Posted

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

#10 ·  Posted

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

A hour spent..

1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted

Congrats on finding the solution on your own! If you check the online help for _FFXPath, you'll find another example using position().

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

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • Omnitica
      By Omnitica
      Hello!
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
       
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
       
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.
       



    • OtenMoten
      By OtenMoten
      Hello dear community,
       
      definitely I need external help now. I've did all 'ControlClick() - Tutorials' and read a lot of topics about interaction betweend AutoIT and external programs.
      The most of them are about "Clicking a button ...". In my case it's different because I need to click a specific element within the program.
       
      The 'program' what I am talking about is called Mendeley. It's library software for documents administration.
       
      In the attachements in picture '1.jpg' you can see the red marked Help element. 
      In the picture '2.jpg' you see the context menu of the Help element. This is what I'm trying to do with the ControlClick() function.
       
      Following I represent my code which not worked for me:
      #include <MsgBoxConstants.au3> Opt("WinTitleMatchMode", 2) $hWnd = WinGetHandle("Mendeley Desktop", "") MsgBox($MB_SYSTEMMODAL, "handle check", $hWnd) ControlClick($hWnd, "Mendeley Desktop", "Help") The MsgBox tells me the number of the handle of the Mendeley window. It's not 0 so for me it means the window is recognized correctly.
       
      When I'm execute the script the Help element is not clicked.
      Any suggestions for me?
       
      Kind regards
      OtenMoten


    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?
       
    • whiskas
      By whiskas
      Hi all,
      I just upgraded to windows 10 and am using Edge as my browser now. Updated my scripts, but I can not unhide a minimized Edge window with the script anymore.
      WinSetState ( "titlle","", @SW_MAXIMIZE ) works fine, but not if it is minimized. Tried same with SW_SHOW, doesn't work.
      WinExists("title","") -> returns 1, so it is finding my window.
       
              WinWait($title,$text,$timeout)
              If Not WinActive($title,$text) Then WinActivate($title,$text)
              WinWaitActive($title,$text,$timeout)
      Doesn't work also, so I think I tried all but cant get the window back
      Any help would be appreciated