Skip to content
Advertisement

Find elements by class name with Selenium in Python

JavaScript

I want to click on elements whose class is “innerImageWrapper editlink”.

I use this code

JavaScript

but it’s not working.

JavaScript

it’s working. but I dont want use xpath. I want use class name

Advertisement

Answer

By.CLASS_NAME receives single value while here you trying to pass 2 values: innerImageWrapper and editlink. To locate element by 2 class names you can use CSS Selector or XPath, but not CLASS_NAME.
So, you can use one of the following:

JavaScript

or

JavaScript

Also, find_elements returns a list of web elements, you can not apply click() on it.
You should use find_element if you want to click on single element or if you want to click on multiple elements you need to iterate over the list of elements and click each one of them, as following:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement