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 Answer(s)

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 http://www.toolsqa.com/automation-practice-switch-windows/

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.

Virender

Virender Singh Professor Answered on June 5, 2015.
Add Comment

Thanks for the update, will try with this

Dineshk Train Answered on June 10, 2015.
Add Comment

Your Answer

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