Python Selenium Webdriver:AttributeError'list'对象没有属性'tag_name' [英] Python Selenium Webdriver: AttributeError 'list' object has no attribute 'tag_name'

查看:932
本文介绍了Python Selenium Webdriver:AttributeError'list'对象没有属性'tag_name'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行代码时,我遇到了select元素的麻烦

I am having a trouble with the select element when I try to run my code it gives me an error

AttributeError 'list' object has no attribute 'tag_name'

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

like I don't have any select element. Is it because it is not focusing on popup? What am I doing wrong?

MyCode.py

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中的错误:

Error in 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_elements_by_xpath returns list of WebElements.

应为find_element_by_xpath.请注意find_element中的s.

这篇关于Python Selenium Webdriver:AttributeError'list'对象没有属性'tag_name'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆