Jump to content

Recommended Posts

Posted

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"]

#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

 

image.thumb.png.1f28727a08e3be59aef7dc4e467e7896.png

image.thumb.png.23df87161a64fc21654a1a7ad95fd293.png

Posted

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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

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

Posted

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.

Func 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

 

  • 1 month later...
Posted

 

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

 

image.png.264d2b191f34b6cbc7b49211ede36804.png

image.png.56bc3ec4d9efac87b213f21464d9da76.png

Posted
  On 8/21/2024 at 6:49 PM, roughmech said:
Local $oTemp = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='firstName']",Default, Default, $sRoot)
Expand  

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)

 

Posted

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

image.png.5767bbd9ec786d5d5d599ec27bf5b6e1.png

image.png.767cd9b63c4573748152e83e6a096482.png

Posted

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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...