🦎Locators
Locators
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
Class Name
Locates elements by matching the CSS class name
driver.findElement(By.className("className"));
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"));
Last updated