python-3.x - 我在 selenium 'NoneType' 对象没有属性 'options' 上收到此错误
问题描述
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脚本时收到此错误我可能知道我为什么会收到此错误以及如何解决此问题
解决方案
只需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)
推荐阅读
- roku - 他们在 Roku 的 onkeyEvent() 中调用 init() 是否正确
- android - Android 如何从 firebase-realtime-database 获取单个记录并显示到 FirebaseRecyclerAdapter
- c# - 访问打印机“PrinterName”的设置无效
- asp.net-mvc - Service Worker - 使用动态参数缓存页面
- reactjs - 将 Ionic Native / Cordova 插件与 Ionic (React) & Capacitor 一起使用的正确方法是什么?
- c++ - 什么是地图的*迭代器
? 这不是对 - php - 在 HTML 中包含 PHP 文件时,表格排序不起作用
- r - rowid_to_column() 和 mutate(rowid = row_number()) 之间的不同行为
- python - FLASK - 如何在我的函数在后台运行时显示加载屏幕,然后从我的函数返回 html 页面?
- spring - Spring依赖注入:需要单个bean