How to find elements having Same ID and Attributes using webDriver

Consider multiple  element (Button) are in Html page with Same  ID and name (i.e. everything same).

Even xpath is also same e.g. mentioned below

a= .//*[@id=’button1′]

for all the multiple buttons

whenever  we use below statement

driver.findelement(By.xpath(a)).click() ,

it always click 1st button in the html page, Remaining buttons are not located.

How can we find the remaining buttons , can you please optimal solution .


Default Asked on August 1, 2015 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Use an ArrayList. Something like:
    ArrayList<WebElement> buttons = driver.findElements(By.xpath(“.//*[@id=’button1”);

    And then do some kind of validations to get the location as to where to click.

    Train Answered on August 6, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.