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

    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • mattia100
      By mattia100
      HI!
      1) I want to create a FF web page in background... i want to say a web page that can't be seen in the application bar  but only in Windows Task Manager... 
      maybe using  __FFStartProcess? in fact i tried to use it but the parameter "hide" only can minimize the page, but not put it in background... 
      2) After creating this hide page, i would to open a macro of the iMacros addon, always all in hide mode...
      it is possible to do it?
      anybody can help me?
      Thanks!!
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • islandspapand
      By islandspapand
      Hi all
      i am currently trying to click on an element in a HTML Table, but just can get it to work.
      i am able to click the top of the table so it changes to sort  but just can't click on the element in the table.
      an i need to click on element to continue in the site.
      i have attached the code so far and pictures of the table  element want to click plus the source of the table.
      i am able to get data in the table with $oTable = _IETableGetCollection($oIE, 2) but not able to click on them.
       
      Help is very much appreciated
       
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <IE.au3> #include "DOM.au3" #include <Array.au3> #include <MsgBoxConstants.au3> Global $oIE = _IECreate("*") _IELoadWait($oIE) Sleep(2000) _PageLogin($oIE) _PageLoadWait() _PageNewReq($oIE) _PageLoadWait() _InputModelInf($oIE) _PageLoadWait() Sleep(1000) $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr/td[.='Name Of user']", 2000) ;~ $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr", 2000) ;~ _ArrayDisplay($aTableLink,"$aTableLink") If IsArray($aTableLink) Then ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF) For $i = 0 To UBound($aTableLink)-1 ConsoleWrite(" OuterHTML : " & $aTableLink[$i].outerHTML & @CRLF) ConsoleWrite(" Parentnode : " & $aTableLink[$i].parentnode & @CRLF) ConsoleWrite(" Parentnode.click : " & $aTableLink[$i].parentnode.fireEvent("onclick","click") & @CRLF) $objClick = $aTableLink[$i].parentnode ;~ _IEAction($aTableLink[$i] , "focus") _IEAction($objClick , "focus") ;~ If _IEAction($aTableLink[$i], "click") Then If _IEAction($objClick, "click") Then ConsoleWrite("Able to _IEAction($aForumLink[0], 'click')" & @CRLF) _IELoadWait($oIE) Else ConsoleWrite("UNable to _IEAction($aForumLink[0], 'click')" & @CRLF) Exit 3 EndIf Next Else ConsoleWrite("Unable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF) Exit 2 EndIf _PageLoadWait() Func _InputModelInf($oTmpIE) ; Add Var for Model & Serial in Func $oModelInput = _IEGetObjById($oTmpIE,"model") _IEAction($oModelInput,"focus") _IEDocInsertText($oModelInput, "*") $oSerialInput = _IEGetObjById($oTmpIE,"serial") _IEAction($oModelInput,"focus") _IEDocInsertText($oSerialInput, "*") $links = $oTmpIE.document.getElementsByClassName("btn btn-primary ng-scope") For $link In $links If $link.innertext = "Søg" Or $link.innertext = "Search" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageNewReq($oTmpIE) $links = $oTmpIE.document.getElementsByClassName("ng-scope k-link") For $link In $links If $link.innertext = "Send ny fejlmelding" Or $link.innertext = "Submit a New Service Request" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageLogin($oTmpIE) $oUserInput = _IEGetObjById($oTmpIE,"loginid") _IEDocInsertText($oUserInput, "*") $oPasswordInput = _IEGetObjById($oTmpIE,"password") _IEDocInsertText($oPasswordInput, "*") $links = $oTmpIE.document.getElementsByClassName("btn btn-primary login ng-scope") For $link In $links If $link.innertext = "Sign in" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageLoadWait() Local $PageLoadWait = False ;~ nav navbar-nav navbar-right ng-hide ;~ nav navbar-nav navbar-right $tags = $oIE.document.GetElementsByTagName("ul") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "nav navbar-nav navbar-right" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage loading :) ' & @CRLF) ;### Debug Console $PageLoadWait = True ExitLoop EndIf Next Do sleep(250) For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "nav navbar-nav navbar-right ng-hide" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage load finished :)'& @CRLF) ;### Debug Console $PageLoadWait = False ExitLoop EndIf Next Until $PageLoadWait = False EndFunc  
      Thanks in advance
       
       


    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?