Zaphiel
Zaphiel

Reputation: 293

Python Selenium - Get Count of Affected Elements by find_element_by_css_selector

I'm trying to get count of affected elements by my css query. But I couldn't able to get count.

browser  = webdriver.Firefox()
browser.get("http://just-a-example.site")
td_weeks = browser.find_element_by_css_selector("td.status") 
# there is 4 elements that have "status" class
print(len(td_weeks)) # it gives me error

Error:

Traceback (most recent call last):
File "main.py", line 59, in <module>
    print(len(td_weeks))
TypeError: object of type 'FirefoxWebElement' has no len()

Thanks for any kind of help.

Upvotes: 0

Views: 2629

Answers (1)

elrich bachman
elrich bachman

Reputation: 176

To find multiple elements (these methods will return a list):

find_elements_by_name
find_elements_by_xpath
find_elements_by_link_text
find_elements_by_partial_link_text
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector

so your code should be like this

browser  = webdriver.Firefox()
browser.get("http://just-a-example.site")
td_weeks = browser.find_elements_by_css_selector("td.status")#this will return list of class
print(len(td_weeks))

Upvotes: 1

Related Questions