RE: How to handle dynamically generated id with XPath

I am currently facing an issue with xpath with dynamically generated ID. i could n’t able to access the element with its xpath because of dynamically geneated id inside the xpath.

Kindly advise

Add Comment
2 Answers

Simple answer is that your xpath showuld not use the ID to identify element, try to reach to the element via relation to parent elements.

On this page

There is aa button “New Browser Window” on this web page. The id of the web element is “button1″. NOw using xpath there are two ways to identify the element. First is directly by ID like this
– //*[@id=”button1″]

Second is by parent child relation of the element
– //*[@id=”content”]/p[2]/button

in your case as ID is changing you cannot rely on the 1 st for of Xpath, the one that uses id.

Also you can use css selector instead, that should be a better approach.


Professor Answered on June 5, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.