如何在python3中使用selenium在javascrip站点中选择下拉列表?

迈克

我被困在以下来自使用 Javascript 的站点的 html 代码中。我想要的是使用 Select 模块在 Selenium 中选择项目“Short_Budget_Report”。html代码如下:

<input id="WD51" ct="CB" lsdata="{1:'20ex',8:'WD52',9:'2347',11:'Short_Budget_Report',14:'Load\x20View',18:'View',44:false,48:'WD51\x2dtlbl'}" lsevents="{Select:[{ResponseData:'delta',ClientAction:'submit'},{}]}" type="text" autocomplete="off" tabindex="0" ti="0" title="Load View" class="lsField__input urEdf2TxtEnbl lsEdfLeftBrdRadius lsEdf3TxtHlpBtn urEdfVAlign urBorderBox lsControl--explicitwidth" readonly="" value="Short_Budget_Report" style="vertical-align:top;width:20ex;">

我尝试过的:

dropdown_id = driver.find_element_by_xpath('//*[@id="WD51"]')
    dropdown = Select(dropdown_id)
    dropdown.select_by_value('Short_Budget_Report')

这给出了以下错误:

raise UnexpectedTagNameException(
selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on <select> elements, not on <input>
哈马德·阿里 |

您可以简单地使用send_keys()函数在下拉列表中选择特定选项。

  1. 首先通过任何find_element()函数定位下拉列表的元素
  2. send_keys()在该元素上使用函数立即从列表中选择任何值

简而言之,按照以下方式进行操作应该可以满足您的需求:

driver.find_element_by_id('WD51').send_keys('Short_Budget_Report')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Python中使用Selenium从站点下载多个文件以选择下拉列表的每个选项

如何在 python 中使用 selenium 选择下拉列表的项目

如何在python和selenium中使用execute_script从下拉列表中选择一个值

如何在python中使用硒从下拉列表中选择一个选项

如何在输入类型的python中使用webdriver selenium选择下拉列表元素?

如何在Python Selenium的下拉列表中选择href这个选项?

Selenium Python:如何从下拉列表中选择项目

如何使用 Selenium 在下拉列表中选择项目?

如何在量角器中使用formcontrolname从下拉列表中选择值?

Python Selenium 如何在谷歌表单中选择下拉选项

从 selenium python 的下拉列表中选择

如何从使用 selenium webdriver 中的 api 响应动态启动的下拉列表中选择特定位置?

如何在Python中通过Plotly从Dash的下拉列表中选择数据集列?

如何在虚拟化列表中使用选择下拉列表?

使用 3 个选择列表中的选项从 Google 站点中的 Google 表格返回表格

如何使用selenium webdriver java从城市字段的GoIbibo中的自动选择下拉列表中选择一个元素

如何在Kentico的多个站点中使用表单?

在下拉列表中选择选项在 selenium 中使用 java 实现 css

在Java中使用Selenium从下拉列表中选择随机WebElement

无法使用Selenium WebDriver选择共享点站点中的下拉菜单

如何在 Vuetify 选择下拉列表中使用标签图标?

如何在 selenium python 中处理没有选择的下拉列表

如何从具有特殊设置的网站上使用Selenium从下拉列表中选择一个值-Python

如何在python3中选择元素的特定值

如何在Python3 Pandas中从每个月中选择最大日期

如何在python3中使用Asterisk AGI?

Selenium WebDriver:如何在跨度下拉列表中选择一个值?

如何在 python 中使用 Selenium 包单击多个复选框和下拉列表?

如何在 Python 中使用 Selenium 单击下拉列表的 li 元素^