Method Syntax Description
By ID driver.findElement(By.id ())Locates an element using the ID attribute
By namedriver.findElement(By.name ())Locates an element using the Name attribute
By class namedriver.findElement(By.className ())Locates an element using the Class attribute
By tag namedriver.findElement(By.tagName ())Locates an element using the HTML tag
By link textdriver.findElement(By.linkText ())Locates a link using link text
By partial link textdriver.findElement(By.partialLinkText ())Locates a link using the link’s partial text
By CSSdriver.findElement(By.cssSelector ())Locates an element using the CSS selector
By XPathdriver.findElement(By.xpath ())Locates an element using XPath query
Selenium supports 8 different types of locators namely id, name, className, tagName, linkText, partialLinkText, CSS selector and xpath. Using id is one of the most reliable and fast methods of element recognition. Usually, the id is always unique on a given web page
Locator can be termed as an address that identifies a web element uniquely within the webpage. Thus, to identify web elements accurately and precisely we have different types of locators in Selenium:ID ClassName Name TagName LinkText PartialLinkText Xpath CSS Selector DOM