Jump to content

Grab chaning xpath by last 3 characters in chrome (WebDriver)


Recommended Posts

Posted (edited)

I have multiple xpaths that are always changing, except for the last 2 or 3 chars is there a way I can grab an xpath that changes like this? Or is there a alternative way I can try to grab these? 

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="in5wO_4"]')  ;;enters dob

    _WD_ElementAction($sSession, $sElement, 'value', FormatDate($sR4))

@mikell was able to help with a similar issue in IE. However, this method wont work. 

$var = "_26"

; $sHTML = '<input name="in2xk_92" class="navitem s_147" id="in2xk_26" style="..." etc>'
$sHTML = _IEDocReadHTML($oIE)
$id = StringRegExpReplace($sHTML, '(?s).*?id="(\w+' & $var & ').*', "$1")
; Msgbox(0,"", $id)
$oInput = _IEGetObjById($oIE, $id)
; etc

 

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Link to post
Share on other sites
Posted (edited)

Have you tried using the xpath ends-with() function?

Here's a nice xpath cheat sheet with examples: https://devhints.io/xpath

Edited by TheXman
Link to post
Share on other sites

Thank you for this link. I appreciate it. 

However, I am still not understanding something here. 

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[ends-with(@id,"_4")]'  ;;enters dob
    _WD_ElementAction($sSession, $sElement, 'value', FormatDate($sR4))

I keep getting a syntax error. 

image.png.27dad4d5a9750b6b3ac1e46bca7db7ca.png

image.png.670787365e6dbc9ea8d3c1bba8009dd2.png

Life's simple. You make choices and you don't look back.

Link to post
Share on other sites

Thanks for the link?  Is that all you want to thank me for?  :think:  If so, I guess I'll add you to my ever increasing list of people to ignore.  ;)

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

    No registered users viewing this page.

×
×
  • Create New...