Locators in Selenium

To perform an action on any element, we first have to locate/find it on the web page through various built-in locator strategies which are being offered by Selenium WebDriver.

How do we identify an element in Selenium? #

WebElement name = driver.findElement(By.id("username"));

Here, the findElement(By) method returns a WebElement object. WebDriver represents the browser and WebElement represents a DOM node (a control, a link, field, etc.). By abstract class used above also supports a number of additional locator strategies, as described below.

WebDriver has multiple methods to identify the WebElement using a locator. https://selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.html

WebElement provides methods to operate upon the locators for performing some actions. https://selenium.dev/selenium/docs/api/java/org/openq ...