TestProject Forum
Powered by leading experts in the test automation community

Find media items with selenium

I have a collection of media items in my app that have the class ‘img-gr’. when I try find element with class name, it finds only the first item, but I want click on the second item.

How can i find item no. 2 ?

Use the findElements method instead of findElement and place them in a list like so:

List<WebElement> elements = driver.findElements(by.id(...));

Then you can access the 2nd item:

elements.get(1).click();