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

时间:2016-03-17 05:27:19

标签: python selenium selenium-webdriver

当我尝试运行我的代码时,我遇到了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 个答案:

答案 0 :(得分:7)

find_elements_by_xpath返回WebElements列表。

应该是find_element_by_xpath。请注意s中的find_element