python - Select is not iterable error while select is not iterable error while select a Dropdown option based on user input using Selenium and Python
问题描述
每次用户输入公司名称时,我都想从用户那里获取输入。所以我收到此错误是否有其他方法可以解决此查询?
from selenium.webdriver.support.ui import Select
from selenium import webdriver as driver
menu = Select(driver.find_element_by_id('BodyContent__company'))
name=input('Enter company name: ')
for option in menu:
if option.text == name:
option.select()
else:
pass
错误:
Select is not iteratable
解决方案
此错误消息...
Select is not iteratable
...意味着在您的代码块中,您正在尝试遍历type 的WebElementSelect
。
解决方案
您需要遍历元素,而不是迭代html-selectSelect.options
元素,如下所示:
from selenium.webdriver.support.ui import Select
from selenium import webdriver as driver
menu = Select(driver.find_element_by_id('BodyContent__company'))
name=input('Enter company name: ')
for option in menu.options:
if option.text == name:
option.click()
else:
pass
推荐阅读
- java - 如何将 Listview 添加到 Listview Android Studio
- django - context 必须是 dict 而不是 set
- jquery - 在第一次提交时无法使用 ckeditor 获取 Textarea 表单的值,但它适用于第二次提交
- java - 使用 Java 在现有 json 文件中附加 json 对象
- r - 随机森林模型中移除响应变量的标准
- python - 在 .py 文件之间定义全局变量的正确方法是什么
- python - ImportError:无法导入名称“后端”
- c# - .NET 中奇怪的委托和操作行为
- corda - corda 节点可以成为多个 corda 网络的一部分吗?一个带有多个 NMS 的 corda 节点可能吗?如何实现私有网管?
- javascript - 在一个命令中运行多个 nodejs 服务器