我正在尝试通过我的 css 查询获取受影响元素的数量。但我无法数清。
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
错误:
Traceback (most recent call last):
File "main.py", line 59, in <module>
print(len(td_weeks))
TypeError: object of type 'FirefoxWebElement' has no len()
感谢您的任何帮助。
要查找多个元素(这些方法将返回一个列表(:
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
所以你的代码应该是这样的
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))