Locators are the way to tell Selenium with which web element we like to do something (Something can be anything, like: clicking, typing, selecting, etc.).
Selenium provides different ways of locating those web elements, we call this the locating strategy. In Selenium 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.
I like to recommend the CSS locating strategy for three reasons:
- It’s faster;
- It’s more readable;
- It’s more used;
It depends on the browser, but in Internet Explorer the XPath locators are 2 (up to 3) times slower then CSS locators. It requires very low maintenance, because the syntax is readable and understandable. Beside of that, CSS locators are more used in projects, for example by designers or jQuery experts (frequently used JavaScript library).
This section of the blog will describe different ways of locating web elements, from very basic web elements (such as: form elements and containers) to the more complex ones (such as: list items and table cells). Related posts are listed below.
