What are the different types of locators in Selenium?
Kapi Shivhare
Select an image from your device to upload
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