Multiple buttons with same type and id

cxyz picture cxyz · Oct 30, 2012 · Viewed 59.5k times · Source

I'm new to Selenium. Below is my code.

<input type="submit" id="button" value="Edit"/>

I have 3 buttons with the same type, id and value. How do I click on each of the buttons? Can anyone help me with the XPath?

Answer

eugene.polschikov picture eugene.polschikov · Oct 30, 2012

I resolved such problem in the following way:

String cssSelectorOfSameElements="input[type='submit'][id='button']";

 List<WebElement> a=driver.findElements(By.cssSelector(cssSelectorOfSameElements)) ;
 a.get(0).click();
//a.get(1).click();
//a.get(2).click();

depends upon what button you need to click on. Hope this works for you.