我在硒“ NoneType”对象没有属性“选项”时遇到此错误

时间:2018-11-08 07:34:36

标签: python-3.x selenium

select = driver.find_element_by_xpath('//select[@id="select_noti_segments_in"]').click()
for index in range(len(select.options)):
        select = driver.find_element_by_xpath('//select[@id="select_noti_segments_in"]')
        select.select_by_index(1)
        time.sleep(5)

用于范围内的索引(len(select.options)): AttributeError:“ NoneType”对象没有属性“ options” 我在运行python脚本时遇到此错误,我可能知道我为什么得到此错误以及如何解决此问题

1 个答案:

答案 0 :(得分:1)

只需从click定义中删除对select的调用:

select = driver.find_element_by_xpath('//select[@id="select_noti_segments_in"]')

此外,您需要导入Select类并按如下方式使用它:

from selenium.webdriver.support.ui import Select

select = Select(driver.find_element_by_id('select_noti_segments_in'))
select.select_by_index(1)