[英]How can I click on multiple drop down list on a page with Python and Selenium?
我正在尝试点击页面上的多个下拉列表,但我一直收到错误,说我的列表对象没有属性tag_name'。
我的代码
def click_follow_buttons(driver):
selects = Select(driver.find_elements_by_class_name("jBa"))#jBa
print selects
for select in selects:
select.select_by_index(0)
driver.find_element_by_class_name("bA").click()
我的追溯
Traceback (most recent call last):
File "google_follow.py", line 50, in <module>
if click_follow_buttons(driver) == False:
File "google_follow.py", line 18, in click_follow_buttons
selects = Select(driver.find_elements_by_class_name("jBa"))#jBa
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/select.py", line 35, in __init__
if webelement.tag_name.lower() != "select":
AttributeError: 'list' object has no attribute 'tag_name'
Html下拉列表
<div class="jBa XG">
<div class="ny dl d-k-l" jslog="7128; track:impression">
首先,您使用的是find_elements_by_class_name()
方法,该方法将返回与类名称匹配的Web元素列表,而不是单个元素。
但是,即使你使用find_element_by_class_name()
,你也会得到一个不同的错误,因为这是一个匹配类名而不是select
元素的div
元素。
您需要传递给Select
类web元素的构造函数,该元素具有select
标记名称: https : //selenium.googlecode.com/git/docs/api/py/webdriver_support/selenium.webdriver.support.select.html
构造函数。 检查给定元素确实是SELECT标记。 如果不是,则抛出UnexpectedTagNameException。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.