How can I filter elements that have the same class?
<html> <body> <p class="content">Link1.</p> </body> </html> <html> <body> <p class="content">Link2.</p> </body> </html>
Luckily, Selenium offers a few methods you can use to find elements. One of the options the Selenium WebDriver library provides for locating HTML elements is the use of the class property. The HTML class property is used for setting a class to an HTML element.
We can find an element using the attribute class name with Selenium webdriver using the locators - class name, css, or xpath.
You can try to get the list of all elements with class = "content"
by using find_elements_by_class_name:
a = driver.find_elements_by_class_name("content")
Then you can click on the link that you are looking for.
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