Locators in Selenium
Explore how to identify web elements in Selenium WebDriver using various locator strategies including id, name, class, css selectors, xpath, and link texts. Understand how these locators help interact with the UI elements effectively in your automation scripts.
We'll cover the following...
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 ...