Showing posts with label xpath. Show all posts
Showing posts with label xpath. Show all posts

Friday, November 4, 2022

Selenium - Xpath Locators

1. By Tagname
 //tagname[@attribute='value'] 
driver.findElement(By.xpath("//input[@placeholder='Name']")) 

2. By index of the attribute 
 //tagname[@attribute='value'][index] 
 driver.findElement(By.xpath("//input[@type='text'][2]")) 
Used when your attribute and the value are same for multiple elements 

3. By tagnames when there are many instances of the childtag. 
 //parenttag/childtag[index]) 
driver.findElement(By.xpath("//form/input[3]")) 
Use index when there are many instances of child tag and you have to locate one of them.) 

 4. By parent to child-tag 
//parenttag[@attribute='value']/childtag[index]) 
driver.findElement(By.xpath(" //div[@class='forgot-pwd-btn-conainer']/button[1]")) 

 5. With regular expression 
 //tagname[contains(@class,'value')] driver.findElement(By.xpath("//button[contains(@class,'submit')]"))

Featured

Selenium - Page Object Model and Action Methods

  How we change this code to PageObjectModel and action classes. 1 2 3 driver . findElement ( By . id ( "userEmail" )). sendKeys (...

Popular Posts