Form the title; you might get an idea about this post. Yes, it is all about how to locate a web element using xpath.
We can locate almost all the elements in the web page using Xpath. As there are a lot of stuffs out there for basic xpath construction, I am going to concentrate specific methods that helped me during my scripting.
Locating a WebElement with unique attribute value:
Let’s assume a scenario where your element has id/class/name with dynamic value. We can do this by the following xpath.
Example HTML :
<a href='iamhere'></a>
Xpath Syntax :
//a[@href= ‘iamhere’]
Consider, when the param also has a partially dynamic value, Now comes other problem. Still we have a breath.
i.e., for the HTML,
<a href='iamhere123456'></a>
Xpath can be built as
//a[contains(@href,'iamhere')]
I would appreciate if you can suggest me some corrections/additions. Anyway, there are lot more to share, Stay tuned.
Thanks for reading.!