When working with Selenium web testing, there are a few ways to identify WebElements.
In my experience, I have used the following selectors:
Locators should be descriptive, unique, and unlikely to change. So my priority is as follows:
::parent and functions like contains().I would avoid LinkText and TagName as they tend to cause unexpected failures due to very generic filtering.
Note on CSS and XPath: Using these with something like //div/li[1]/*/span[2] or div > li:nth-child(1) should also be avoided as they depend on the rendering and prone to changes.