Davidowicza Posted November 5, 2018 Share Posted November 5, 2018 (edited) Hey guys, I am creating my very first script that automates a browser (I usually work with program installs and database automation) and have come across an issue that I am totally stumped on. I need to click an element that gives me a drop down list box but the Xpath to the element changes with every instance of chrome I start... I have tried selecting the class, rect, and path but no luck. It never finds the element. (I could be doing this wrong since I am not good at HTML) Element I need to select: Quote <g class="highcharts-button highcharts-contextbutton highcharts-button-normal" style="cursor:pointer;" stroke-linecap="round" transform="translate(994,10)"> <title>Chart context menu</title> <rect fill="#ffffff" class=" highcharts-button-box" x="0.5" y="0.5" width="24" height="22" rx="2" ry="2" stroke="none" stroke-width="1"></rect> <path fill="#666666" d="M 6 6.5 L 20 6.5 M 6 11.5 L 20 11.5 M 6 16.5 L 20 16.5" class="highcharts-button-symbol" data-z-index="1" stroke="#666666" stroke-width="3"></path><text x="0" data-z-index="1" style="font-weight:normal;color:#333333;fill:#333333;" y="12"></text> </g> This is the Xpath for the last 3 instances of chrome I have run the script with: //*[@id="highcharts-5bp9crq-8"]/svg/g[6]/g/rect //*[@id="highcharts-fiw9szv-8"]/svg/g[6]/g/rect //*[@id="highcharts-5szkmx8-8"]/svg/g[6]/g/rect As you can see the path changes every time. How I am trying to select the element: ;Check for box element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") MsgBox(0, "", "check for timeout") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") _WD_ElementAction($sSession, $sElement, 'click') Maybe someone has come across this before and found a work around without using mouseclick() Thanks guys, hopefully I am just very overlooking something simple and can be pointed to the right solution. Side Note: I wish I could share the webpage entirety, but it has sensitive information with my agency that I cannot share. If you need more, just let me know and I will try and post as much as I can. Edited November 7, 2018 by Davidowicza Link to comment Share on other sites More sharing options...
Danp2 Posted November 5, 2018 Share Posted November 5, 2018 Is this a website that you can share? I find these issues so much easier to resolve when I can actually testing out things. Have you tried using "//rect[@class='highcharts-button-box']" as the xpath? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Davidowicza Posted November 5, 2018 Author Share Posted November 5, 2018 11 minutes ago, Danp2 said: Have you tried using "//rect[@class='highcharts-button-box']" as the xpath? I did not but just tried and it still times out. You need to log in to access the site so it would be pointless to share it. :/ Link to comment Share on other sites More sharing options...
Davidowicza Posted November 5, 2018 Author Share Posted November 5, 2018 (edited) If it help, this is what the button looks like: I know it doesn't really provide more information, but I am trying to give as much as possible. Edited November 5, 2018 by Davidowicza Link to comment Share on other sites More sharing options...
Danp2 Posted November 5, 2018 Share Posted November 5, 2018 Not sure what you mean by "times out". Please explain. Maybe it would help if you showed the results from the Scite output window. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Davidowicza Posted November 5, 2018 Author Share Posted November 5, 2018 I was using a Msgbox to appear after I did a _WD_WaitElement to see how long it would wait for until it continued and as you know _WD_WaitElement will wait by a default 10 seconds if it does not find a match before continuing, so when it waited for 10 seconds I called it "timing out", meaning it never found it. I should have error checked like this: _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//rect[@class='highcharts-button-box']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//rect[@class='highcharts-button-box']") If @error = $_WD_ERROR_NoMatch Then MsgBox(0, "", "No Match") EndIf _WD_ElementAction($sSession, $sElement, 'click') in short, it is still showing No Match. Link to comment Share on other sites More sharing options...
Danp2 Posted November 5, 2018 Share Posted November 5, 2018 (edited) This works for me. Let me know if you can make it work with your website -- #include <wd_core.au3> #include <wd_helper.au3> Local $sDesiredCapabilities, $sElement SetupGecko() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.highcharts.com/demo/line-basic") _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, ".highcharts-button-box") If @error = $_WD_ERROR_Timeout Then MsgBox(0, "", "Timeout") Else _WD_ExecuteScript($sSession, "jQuery('.highcharts-button-box').click()") EndIf Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":[' & " ""disable-infobars""" & "" & '] }}}}' EndFunc ;==>SetupChrome Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('DriverParams', '--log trace') _WD_Option('Port', 4444) $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}' EndFunc ;==>SetupGecko Edit: Note the change to the line checking @error. Edited November 5, 2018 by Danp2 Davidowicza 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Davidowicza Posted November 5, 2018 Author Share Posted November 5, 2018 Thanks, I will try this on Wednesday since it is the end of the day and our office is closed tomorrow. Will let you know how it goes! Link to comment Share on other sites More sharing options...
Davidowicza Posted November 7, 2018 Author Share Posted November 7, 2018 @Danp2 You're a genius! Works like a charm now. Thanks so much! Link to comment Share on other sites More sharing options...
Davidowicza Posted November 7, 2018 Author Share Posted November 7, 2018 Sorry, follow up question: My script runs great when not compiled. But after I compile it and run it, I get a popup for every _WD_WaitElement that pauses my script. I don't understand why as a .au3 it runs fine but as an .exe that happens. Is there a flag I need to turn off before compiling? Link to comment Share on other sites More sharing options...
Danp2 Posted November 7, 2018 Share Posted November 7, 2018 This is coming from the __WD_Error function, which is called by the primary _WD functions. Sounds like you have $_WD_DEBUG set to $_WD_DEBUG_Info Either change this to $_WD_DEBUG_None / $_WD_DEBUG_Error or change $_WD_ERROR_MSGBOX = False. Davidowicza 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Davidowicza Posted November 7, 2018 Author Share Posted November 7, 2018 Quote change $_WD_ERROR_MSGBOX = False. Thank you again! This worked very easily. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now