naheliegend
naheliegend

Reputation: 197

Selenium Python - get elements and click on each

i want to store elements in a list and click on each of them one by one. But I have to reach the < u > - Element, because .click() only works, when I click on that < u > - xpath and not on the class-Element.

<a href="javascript:doQuery(...);" class="report">
    <u>Test1</u>

<a href="javascript:doQuery(...);" class="report">
    <u>Test2</u>

<a href="javascript:doQuery(...);" class="report">
    <u>Test3</u>

Any tips? Thanks.

Upvotes: 0

Views: 312

Answers (1)

sytech
sytech

Reputation: 41209

You can use a CSS selector for this.


selector = '.report > u'

elements = driver.find_elements_by_css_selector(selector)

for elem in elements:
    elem.click()

This selector .report > u will select all <u> elements whose parent is an element with the report class.

reference

Upvotes: 1

Related Questions