I have a 2 elements on my web page that has the same class name and I am trying to access the second element and I am unable to do that.
The span looks like this:
<span class="REPORTING_DASHBOARDS__link navMenuLabel ">
Dashboards
</span>
My code for this part looks like this:
dashboards_button = driver.find_element_by_css_selector(".REPORTING_DASHBOARDS__link.navMenuLabel")[1]
dashboards_button.click()
You have to use find_elements_
instead of find_element_
to get all element.
find_element
returns only first possible element.
dashboards_button = driver.find_elements_by_css_selector(".REPORTING_DASHBOARDS__link.navMenuLabel")[1]
Or using nth-child if it is under same parent with find_element
dashboards_button = driver.find_element_by_css_selector(".REPORTING_DASHBOARDS__link.navMenuLabel:nth-child(1)")
if it is not under same parent, change it to xpath,
dashboards_button = driver.find_element_by_xpath("//[contains(@class,'REPORTING_DASHBOARDS__link navMenuLabel')][1]")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With