Quality Testing

Quality is delighting customers

How to handle dynamically change xpath in selenium webdriver?

handle dynamically change xpath in selenium webdriver?

Views: 123

Reply to This

Replies to This Discussion

Hi Madhavi,

If I am getting you right, then, with "Dynamically change xpath", you mean to say that the 'ID' or any other attribute of a web-element changes dynamically in your application.

This is a very common issue faced by an engineer providing test automation services.

You can handle this by any of the following methods:

1. You can use absolute xpath where you need not to give any attribute name In xpath:


2. You can use starts-with function. In this method, you can give that part of web-element ID, which remains same every time.

e.g. //div[starts-with(@id,'post-body-')]/div[4]/form[1]/input[1]

3. You can use 'contains' function:

e.g. //div[contains(@id,'post-body-')]/div[1]/form[1]/input[1]

Hope this helps.


Thank you so much Anand!


TTWT Magazine





© 2018   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service