In this tutorial, we will learn different types of Locators in Selenium Webdriver. The locators are used to identify web page elements. The Selenium Webdriver class with the methods defined for locating elements on the web page.
Types of Locators
The locators are broadly classified into two types:
- Attribute based Locators
- Structure based Locators
Attribute based Locators
Attribute based locators reply on the attributes of the web elements. Examples of Attribute based locators are Id, Name, LinkText, ClassName and TagName.
Structure based Locators
Structure based locators reply on the structure of the page DOM(Document Object Model) to find the web elements. Examples of this type of locators are XPath and CSS Selectors.
By abstract class
Selenium Webdriver provides an abstract class By with static methods that has implementations to locate elements within web pages. Some of the static methods in this class are as follows:
We can create custom locating mechanisms by extending the By class. We can override the finding methods to provide custom locating strategy.
Difference between findElement() and findElements() methods:
Selenium Tutorials on this website: