xpath locator in selenium

Inspect the element in Chrome, then CTRL+F, try to locate your element, like //input[@name=’email’], until you get only one result!

Some sample xpath locator:

link
//a[text()=’Features’]
//a[contains(text(),’Features’)]
button
//button[@type=’button’ and @class=’btn’]
//button[contains(text(), ‘Sign Up’)]
//div[@class=’dropdown’]//button[@type=’button’ and @class=’btn btn dropdown’ and @id=’dropdownMenu’]
//button[@id=’dropdownMenu’]
checkbox
//a[text()=’test2 test2′]//parent::td[@class=’datalistrow’]//preceding-sibling::td[@class=’datalistrow’]//input[@nmae=’contact_id’]
driver.findElement(By.xpath("//a[text()=’test2 test2′]//parent::td[@class=’datalistrow’]//preceding-sibling::td[@class=’datalistrow’]//input[@nmae=’contact_id’]")).click()

Leave a Reply

Your email address will not be published. Required fields are marked *