Locators are the way to tell Selenium WebDriver with which web element we like to do something (It can be literally anything, like: `clicking`, `typing`, `selecting`, `verifying`, and so on).
Selenium WebDriver provides different ways of locating those web elements; we call this the locating strategy. In Selenium WebDriver we can locate web elements by CSS, XPath, Name, Id, and even Link text. We have to define the locators our self, so we have full control over it.
The CSS locating strategy is recommended for three reasons:
- It’s faster;
- It’s more readable;
- It’s more used.
It becomes unnecessary hard to interact with elements on the page if there are no unique identifiers. So, try to convince the developers to add some handy identifiers.
General advice might be to use the locator strategies in the following order: id > name > CSS > XPath > angular. Only use XPath if we need to walk up the DOM.