如何在带有Python和Selenium的页面上单击多个下拉列表?

2024-09-27 19:18:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在一个页面上点击多个下拉列表,但是我一直收到一个错误消息,说我的列表对象没有属性标记“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()

我的回溯

^{pr2}$

Html下拉列表

^{3}$

Tags: 对象name消息列表by属性driver错误
2条回答

首先,您使用的是find_elements_by_class_name()方法,它将返回一个匹配类名而不是单个元素的web元素列表。在

但是,即使使用find_element_by_class_name(),也会得到不同的错误,因为这是一个与类名匹配的div元素,而不是select元素。在

您需要传递给Select类web元素的构造函数,该元素具有select标记名: https://selenium.googlecode.com/git/docs/api/py/webdriver_support/selenium.webdriver.support.select.html

Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.

相关问题 更多 >

    热门问题