当我尝试运行我的代码时,我遇到了select元素的问题,它给了我一个错误
AttributeError 'list' object has no attribute 'tag_name'
就像我没有任何选择元素 . 是因为它不关注弹出窗口吗?我究竟做错了什么?
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 回答
find_elements_by_xpath
返回WebElements列表 .它应该是
find_element_by_xpath
. 注意find_element
中的s
.