XPath: Find element by ID when disregarding a certain character

45 views
Skip to first unread message

Kai E. Frøland

unread,
Jul 21, 2017, 7:49:24 AM7/21/17
to Selenium Users
Hi friends,
I am sure a question like this has been answered before, but I couldn't find anything when searching through the existing answer base.

I am generating automated testing scripts for a web application with dynamically generated pages. (based on some configuration sheets) Some of the elements I need to interact with will have IDs that are impossible to know exactly a priori, but they will always be equal up to a certain point - namely the inclusion or not of colon characters.


Concretely, I have element IDs on this form - and I use XPaths to find them;

In one instance I can find the element by the XPath

//*[@id="nav:form:G:0:R:1:C:0:da"]

but in another instance it may be

//*[@id="nav:form:G0:R1:C0:da"]

I know the element IDs will always be the same if you exclude all the colons. Is it possible to write one XPath that will hit either case?

pranab singh

unread,
Jul 21, 2017, 9:02:33 AM7/21/17
to seleniu...@googlegroups.com
Hi Froland,

You can use your xpath by contains.

Eg- //*[contains(@id,'nav:form:G0:')].

Do please try the above 


Thanks
Pranab Chetri

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/03e9d78e-c0d1-4dfb-90d5-f235daae50b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages