Quality is delighting customers
handle dynamically change xpath in selenium webdriver?
Tags:
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:
e.g.
//html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div[1]/form[1]/input[1]
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.
Thanks
Anand
Thank you so much Anand!
© 2022 Created by Quality Testing.
Powered by