首页 文章

Python Selenium Webdriver:AttributeError 'list' object没有属性'tag_name'

提问于
浏览
0

当我尝试运行我的代码时,我遇到了select元素的问题,它给了我一个错误

AttributeError 'list' object has no attribute 'tag_name'

就像我没有任何选择元素 . 是因为它不关注弹出窗口吗?我究竟做错了什么?

enter image description here

MyCode.py

from selenium import webdriver
from selenium.webdriver.support.ui import Select

browser = webdriver.Firefox()
browser.get("http://www.punjnud.com/PageList.aspx?BookID=14050&BookTitle=Ali%20Zaryoun%20Ki%20Ghazalein")

popupSelect=Select(browser.find_elements_by_xpath("(//select[@class='custom-dropdown selectdrop'])[1]"))

popupSelect.select_by_value("1")

browser.find_elements_by_class_name("btn btn-success").click()

select.py中的错误:

if webelement.tag_name.lower() != "select":
    raise UnexpectedTagNameException("Select only works on <select> elements, not on <%s>" %webelement.tag_name)

例外:

AttributeError: 'list' object has no attribute 'tag_name'

1 回答

  • 7

    find_elements_by_xpath 返回WebElements列表 .

    它应该是 find_element_by_xpath . 注意 find_element 中的 s .

相关问题