Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
191 views
by The go-to Tester (218 points)
I am trying to automatate a selection list. All the elemnet shave same Id. How can I select/click indivisual item from the list. I am using Selenium 3.0.1 and My OS is windows 10. I am writing test in Java language.

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

You can get all elements by using findElements function.

Eg. You have 10 elments with similar ID "mySimilarId", you can first identify all 10 elements using findElements method. It will return List of WebElements.

 

java.util.List<WebElement> elements = driver.findElements(By.id("mySimilarId"));

 

From the variable elements you can access each element by using get() function.

elements.get(0) //will return you the first element.

elements.get(elements.size() - 1) //will return you the last element.

 

Hope that helps! Feel free to write back if you have any questions.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...