我在尝试运行代码时遇到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'
find_elements_by_xpath
返回WebElement的列表。
应该是find_element_by_xpath
。注意s
中的find_element
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句