Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Finding elements by class name in python

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> 
like image 751
Sree Avatar asked May 02 '15 12:05

Sree


People also ask

Can I find element by class Selenium Python?

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.

Can we find element based on class name using Selenium?

We can find an element using the attribute class name with Selenium webdriver using the locators - class name, css, or xpath.


1 Answers

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.

like image 181
LittlePanda Avatar answered Sep 21 '22 12:09

LittlePanda