Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple buttons with same type and id

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?

like image 537
cxyz Avatar asked Oct 30 '12 06:10

cxyz


2 Answers

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.

like image 168
eugene.polschikov Avatar answered Nov 05 '22 11:11

eugene.polschikov


use index based xpath like //input[1] and //input[2] and so on.

like image 40
Abhishek_Mishra Avatar answered Nov 05 '22 13:11

Abhishek_Mishra