Is it best to use Web ID, Name, Css Selector, or XPath when creating a Web Locator?

When creating a Web Locator, it is best to use the most stable identifier possible. If the Web ID or Name looks to be static (not generated), then it is best to use one of those. If these do not look to be static (may contain random digits or letters), or if the element does not have a Web ID or Name, it is better to use XPath.

XPath is an expression used to locate html elements on the screen. You can think of it as a query language to target elements on the page.

There are best practices in XPath that will help ensure that a more stable and accurate Web Locator is created. This is important because as the web application's structure changes over time, fewer (if any) adjustments to the XPath will be needed.

Here is an XPath tutorial:

https://subject7.zendesk.com/hc/en-us/articles/360056716554-XPath-Tutorial-A-Practical-Approach-for-Selenium-Users

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.