Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through multiple class using find_element_by_class_name in Selenium

I am using Selenium webdriver in Python for a web-scraping project.

The webpage, I am working on has a number of Table entries with the same class name.

<table class="table1 text print">

I am using find_element_by_class_name. However I am getting a error :

*Compound class names not permitted *

Another question:

How to iterate through all the tables having the same css classname ?

Thanks

like image 625
Kiran Avatar asked Nov 29 '25 00:11

Kiran


2 Answers

You should use find_elements_by_class_name. This will return an iterable object.

like image 173
Geo Avatar answered Nov 30 '25 14:11

Geo


The error you describe happens when you provide multiple class names rather than a single one. An easy way around this is to get the elements using CSSSelector or XPath. Alternatively, you could use find_elements_by_class_name and provide one class name, then iterate through that list to find the elements that match the additional class names you want to match on as well.

like image 26
Sam Woods Avatar answered Nov 30 '25 13:11

Sam Woods



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!