0
我遇到了select元素的問題,當我嘗試運行我的代碼時,它給了我錯誤AttributeError'list'object has no attribute'tag_name'like我沒有任何選擇元素。這是因爲它不關注彈出窗口嗎?我究竟做錯了什麼?對不起,我從來沒有使用硒,需要一些指導。Python Selenium Webdriver:AttributeError'list'對象沒有屬性'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'
你如何初始化'webelement'變量? – JRodDynamite
我找到xpath的元素並將其存儲在mySelect變量中MyCode.py –