roughmech Posted July 16 Share Posted July 16 Hello, I have been using the WebDriver UDF for the first time since the website I am trying to automate will not work with the IE method that I'm used to programming with. This is also the first time using XPaths. I have studied Getting Started and have a grasp of the basics. I'm just having issues finding the elements. I installed the dev tools into my Chrome browser for identifying elements also. My program uses Edge to load the site for automation, Edge was the first browser I got to work with the WebDriver UDF. While using the automation I thought it would be good not to have other instances of the same browser open that I was trying to automate. I just cant figure out why the elements dont match the selector as shown below. ChroPath says This element might be pseudo element/comment/inside iframe from different src. I also tried absolute path on the email input and still no match /html/body/div[1]/div[3]/div/div[2]/div/div/form/div[2]/div[1]/input Thank you Element relative path text from the website using the Copy. Email input //*[@id="InputIdentityFlowValue"] Continue button //*[@id="BtnSubmit"] expandcollapse popup#Region - include files ; non standard UDF's #include "wd_helper.au3" #include "wd_capabilities.au3" #include "wd_core.au3" #EndRegion - include files #Region - Global's declarations Global Const $sElementSelector = "//input[@name='q']" #EndRegion - Global's declarations Local $sDesiredCapabilities, $sSession, $sElement SetupEdge() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) DisneyLogin() Func SetupEdge() _WD_Option('Driver', 'msedgedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe", "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false}}}}' EndFunc Func DisneyLogin() Local $sElement, $sButton _WD_Navigate($sSession, "https://disneyworld.disney.go.com/login/") sleep(1000) ;Locate email input element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='InputIdentityFlowValue']") Sleep(500) ; Set email input element's contents _WD_ElementAction($sSession, $sElement, 'value', "someone@somewhere.com") Sleep(500) ; Locate continue click element $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='BtnSubmit']") ; click continue element _WD_ElementAction($sSession, $sButton, 'click') _WD_LoadWait($sSession, 2000) EndFunc Link to comment Share on other sites More sharing options...
mLipok Posted July 16 Share Posted July 16 Firstly I see only loading spinner. Constantly. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
mLipok Posted July 16 Share Posted July 16 btw. you should not use sleep for every single job. Try to wait on loading eventually wait on desired element, Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Danp2 Posted July 16 Share Posted July 16 That website uses iframes. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
roughmech Posted July 16 Author Share Posted July 16 Thank you very much for the reply. I will be removing the sleep statemets, they were just there as I trying to figure out what was going on. Danp2, thanks for the verifications of iframes. I did a search with "iframe" and found one where you responded with a solution. I am going to try that. I'll get back to you all with the results. Thank you Link to comment Share on other sites More sharing options...
roughmech Posted July 18 Author Share Posted July 18 I understand now how to work with the iframes. Find the frame with FindElement with a wait, then enter the frame with FrameEnter and then find the element using FindElement again, using relative Xpath. Working script below, thanks again for your help. expandcollapse popupFunc DisneyLogin() Local $sElement, $sButton, $sXpath, $sEmailInput _WD_Navigate($sSession, "https://disneyworld.disney.go.com/login/") _WD_LoadWait($sSession, Default, 10 * 1000) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $sXpath) ConsoleWrite("Frames Count=" & _WD_GetFrameCount($sSession) & @CRLF) ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF) ;Locate email frame element $sXpath = "//iframe[@id='oneid-iframe']" $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sXpath) _WD_FrameEnter($sSession, $sElement) ;Locate email element $sEmailInput = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='InputIdentityFlowValue']") ; Set email input element's contents _WD_ElementAction($sSession, $sEmailInput, 'value', "someone@somewhere.com") ; Locate continue click element $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='BtnSubmit']") ; click continue element _WD_ElementAction($sSession, $sButton, 'click') _WD_LoadWait($sSession, 2000) ;Locate password input element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sXpath) _WD_FrameEnter($sSession, $sElement) $sEmailInput = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='InputPassword']") ; Set email input element's contents _WD_ElementAction($sSession, $sEmailInput, 'value', "password") ; Locate continue click element $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='BtnSubmit']") ; click continue element _WD_ElementAction($sSession, $sButton, 'click') _WD_LoadWait($sSession, 2000) EndFunc bdr529 1 Link to comment Share on other sites More sharing options...
roughmech Posted August 21 Author Share Posted August 21 So I have run into another issue where I cant find an element. This Time it is in a shadow-root. I have search many examples of how to locate the shadow element. I then use what I found _WD_GetShadowRoot in the _WD_FindElement and of course "No match". All of the examples I found have different html above the shadow-root then I show in the pic. The below code is what I have so far and I beleive it has to do with the selectors I'm using but I am not sure because I do not understand the object that has the shadow-root. The pics will show the form I am trying to fill out and the html which has multiple #shadow-root (open) . I did not see the shadow elements nested in anyway just each one under fnf-search-guest-form object further down. If I could figure out how to just find the firstName, I'm sure the rest can be found with the same method. Could you point me in the right direction. Thank you Local $sRoot = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByXPath, "/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input") Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='firstName']",Default, Default, $sRoot) _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//span[@class='required'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Get ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=property Option=header-title __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//span[@class='required'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Get ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=property Option=header-title __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input StartNodeID= Multiple=Default ShadowRoot=Default __WD_Get ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=shadow Option=Default _WD_GetShadowRoot ==> Success [0] : Parameters: Strategy=xpath Selector=/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input StartElement=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//input[@id='firstName'] StartNodeID=Default Multiple=Default ShadowRoot=f.579667ED473876E9446565712A668AE9.d.11CA3D8E4F44456DC048A1012F76EC0B.e.182 Link to comment Share on other sites More sharing options...
Danp2 Posted August 21 Share Posted August 21 1 hour ago, roughmech said: Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='firstName']",Default, Default, $sRoot) This looks incorrect to me. This is the syntax as shown in the help file -- _WD_FindElement($sSession, $sStrategy, $sSelector[, $sStartNodeID = Default[, $bMultiple = Default[, $bShadowRoot = Default]]]) Using this syntax with your original line of code, I get this -- Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='firstName']", $sRoot, Default, True) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
roughmech Posted August 22 Author Share Posted August 22 Thanks Danp2, I changed the FindElement, should of caught that I had passesed $sRoot in the wrong place. The return is giving Invalid Expression now, the StartNodeID does not look right. Searching all the examples of finding a Shadow Root the element above it is what was used, as highlighted in the pic. Typically CSS Selector was used, I used Xpath selector because CSS would not return Success. When I hover over the elemnet highlighted in the first pic the form shows the CSS, i think. I tried that in a CSS Selector but it returned No match. From what I understand so far that element includes the shadow-root which has the elemnet i'm looking for. What do you think is the proper way to look for the shadow-root? Local $sRoot = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByXPath, "/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input") Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='firstName']", $sRoot, Default, True) _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input StartNodeID= Multiple=Default ShadowRoot=Default __WD_Get ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=shadow Option=Default _WD_GetShadowRoot ==> Success [0] : Parameters: Strategy=xpath Selector=/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input StartElement=Default _WD_FindElement ==> Invalid Expression [11] : Parameters: Strategy=xpath Selector=//input[@id='firstName'] StartNodeID=f.2A9C944BAE458A667410AA61E71035B5.d.77682C0C75BF6C40FBD774300486D1F2.e.205 Multiple=Default ShadowRoot=True Link to comment Share on other sites More sharing options...
Danp2 Posted August 22 Share Posted August 22 There is code in _WD_FindElement to ensure that a relative selector is being used when using xpath strategy with a starting node, so this is the reason your code is failing. You should try changing your xpath from "//input[@id='firstName']" to "./input[@id='firstName']" Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
roughmech Posted August 22 Author Share Posted August 22 I looked at the _WD_FindElement in the wd_core.au3 and I see the code you are talking about. I changed my xpath as you suggested and I get Invalid Argument in the output. Local $sRoot = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByXPath, "/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input") Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "./input[@id='firstName']", $sRoot, Default, True) _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input StartNodeID= Multiple=Default ShadowRoot=Default __WD_Get ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=shadow Option=Default _WD_GetShadowRoot ==> Success [0] : Parameters: Strategy=xpath Selector=/html/body/fnf-root/profile-layout/div/fnf-add-guest/div/div/fnf-search-guest-form/div/form/div[1]/div[1]/wdpr-input StartElement=Default __WD_Post ==> Invalid argument [5] : HTTP status = 400 _WD_FindElement ==> Invalid argument [5] : Parameters: Strategy=xpath Selector=./input[@id='firstName'] StartNodeID=f.9D1F09F63ADB2347871FE18F6E0845BE.d.BD269A268D76F73C6792B60BC7174C12.e.196 Multiple=Default ShadowRoot=True 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