๐ฆLocators
Last updated
Last updated
Locators are used to identify web elements on a web page. They are used by WebDriver commands to find web elements.
๐ก Selenium command to operate on GUI elements; right-click the cursor anywhere to access the โInspectโ option
ID
Locates an element by its unique ID attribute
driver.findElement(
);
Class Name
Locates elements by matching the CSS class name
driver.findElement(By.className("className"));
Name
Locates elements by the name attribute
driver.findElement(
);
Tag Name
Locates elements by the HTML tag name
driver.findElement(By.tagName("tagName"));
Link Text
Locates anchor elements with exact link text
driver.findElement(By.linkText("linkText"));
Partial Link Text
Locates anchor elements with partial link text
driver.findElement(By.partialLinkText("partialLinkText"));
CSS Selector
Locates elements using CSS selectors
driver.findElement(By.cssSelector("cssSelector"));
XPath
Locates elements using XPath expressions
driver.findElement(By.xpath("xpathExpression"));