Dinu
Dinu

Reputation: 933

Element having same xpath

I have 3 date calenders in the application and all calenders are having same id, xpath, name and css. I have used the option driver.findElement(By.xpath("//*[@id='imgIRBDate'][2]")).click(); to click on the second element. But it is showing Exception in thread "main" org.openqa.selenium.NoSuchElementException. How to select the second element?

Upvotes: 0

Views: 115

Answers (1)

Husam
Husam

Reputation: 1105

You have to enclose complete xpath in brackets. Try following:

driver.findElement(By.xpath("(//*[@id='imgIRBDate'])[2]")).click();

Upvotes: 1

Related Questions