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脚本时遇到此错误,我可能知道我为什么得到此错误以及如何解决此问题
答案 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)