Randomblue
Randomblue

Reputation: 116333

Get n'th element with given class name with WebDriver

I'm using .find_element_by_class_name() to get an element with a given class name. It seems that the returned element is the first with the class name. How can I get the n'th element with that class name?

Also, is it possible to get all the DOM elements with a given class name?

Upvotes: 2

Views: 2320

Answers (1)

Russell Dias
Russell Dias

Reputation: 73332

There is a find_elements_by_class_name, notice the elements (plural) method which returns an iterator. To find the n'th element simply replace num: find_elements_by_class_name('className')[num]

This should return all DOM elements with the same class name.

Upvotes: 2

Related Questions