Locators in Selenium

To locate a web element we use  findElement method e.g. driver.findElement(By.id(“idname”)). Here the id is a locator there total 8 locators supported by selenium

Locator HTML Tag Accessing using selenium Description
id <input type=”text” id=”email” />

 

WebElement Element = driver.findElement(By.id(“email”)); Locate Element using a id
name <input type=”text” name=”email” /> WebElement Element = driver.findElement(By.name(“email”)); Locate Element using a Name
LinkText < a href=http://google.com> My link </a> WebElement Element = driver.findElement(By.linkText(“My Link”)); Locate Element using a Link text
Partial

LinkText

< a href=http://google.com> My link </a> WebElement Element = driver.findElement(By.partialLinkText (“My “)); Locate Element using a partial Link text
TagName <input type=”text” name=”email” /> WebElement Element = driver.findElement(By.tagName (“input”)); Locate Element using a Tag Name
ClassName <input type=”text” name=”email”  class=”css”/> WebElement Element = driver.findElement(By.className (“css”)); Locate Element using a class
css elector css=input[id=email] WebElement Element = driver.findElement(By.cssSelector(“input[id=email’]”)); Locate Element using a css selector
xpath Click here for xpath tutorial WebElement Element = driver.findElement(By.xpath(“//tr/td “)); Locate Element using a xpath

 


Search

Subscribe to YouTube

Training on Selenium

Like us on facebook

Jobs

Jobs

Cooking with Amol