Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从下拉列表(复选框列表)中选择元素_Python_Selenium - Fatal编程技术网

Python 如何从下拉列表(复选框列表)中选择元素

Python 如何从下拉列表(复选框列表)中选择元素,python,selenium,Python,Selenium,我需要能够从下拉列表中选择一个项目(列表中的项目是复选框),但我似乎无法获得正确的代码。该网页是一个内部网站,因此我无法提供实际链接,但以下是它们的元素: 要激活下拉列表,请执行以下操作: <input name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue" type="text" size="28" readonly="readonly" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_txtVa

我需要能够从下拉列表中选择一个项目(列表中的项目是复选框),但我似乎无法获得正确的代码。该网页是一个内部网站,因此我无法提供实际链接,但以下是它们的元素:

要激活下拉列表,请执行以下操作:

<input name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue" type="text" size="28" readonly="readonly" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_txtValue" title="Support Group report parameter" class="null">
什么都不做

列表框的完整HTML:

<div onactivate="event.cancelBubble=true;" style="white-space:nowrap;">
<input name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue" type="text" size="28" readonly="readonly" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_txtValue" title="Support Group report parameter" class="null"><input src="/sites/pa/reports/Reserved.ReportViewerWebPart.axd?OpType=Resource&amp;Version=11.0.5058.0&amp;Name=Microsoft.Reporting.WebForms.Icons.MultiValueSelect.gif" name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$ddDropDownButton" type="image" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_ddDropDownButton" alt="Select a value" title="Select a value" style="vertical-align:top;cursor:pointer;">
</div>


它什么也不做?它是抛出一个
NoTouchElementException
,还是只是没有做出您想要的选择?您是否尝试过使用
驱动程序通过Selenium执行javascript。执行脚本($get($get($m_sqlRsWebPart\u ctl00\u ctl19\u ctl06\u ctl09')。控件。onValidValue单击(这个,'m_sqlRsWebPart\u ctl19\u ctl06\u ctl09\u divDropDown\u ctl00'))”)
它只是没有做出我想要的选择——我正在使用pythonI只是试图获取上下文;单击文本输入如何激活下拉菜单?仅仅从元素上很难判断这是怎么可能的。如果它实际上没有激活下拉菜单,则您试图从下拉菜单中选择的元素可能仍然隐藏,这可以很好地解释为什么Selenium找不到它。如果您的下拉列表是建议列表:尝试将一些字符作为
驱动程序发送到输入字段。通过css选择器(“输入”)查找元素[type=“text”]”。发送密钥(“一些文本”)
-这应该会激活下拉列表。您还可以共享更多的HTML以使问题更清晰,您收到的错误消息是什么?您是否添加了一些隐式等待?它什么也不做?它是否抛出一个
NoTouchElementException
,或者它只是没有做出您想要的选择?您是否尝试过通过S执行javascript带有
驱动程序的元素。执行_脚本($get($get('m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09')。控件。onValidValue单击(此,'m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_divDropDown_ctl00'))
它只是没有做出我想要的选择——我使用的是pythonI,我只是试图获取上下文;单击文本输入如何激活下拉菜单?仅从元素很难判断这是如何实现的。如果它实际上没有激活下拉菜单,则您尝试选择的元素可能是from下拉列表仍然隐藏,这可以很好地解释为什么Selenium找不到它。如果您的下拉列表是建议列表:尝试将一些字符作为
driver发送到输入字段。通过css选择器(“input[type=“text”]”)查找元素。发送键(“一些文本”)
-这应该会激活下拉列表。您还可以共享更多的HTML以使问题更清楚,您收到的错误消息是什么?您是否添加了一些隐式等待?
driver.find_element_by_name("m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue").click()
driver.find_element_by_id("m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_divDropDown_ctl184").click()
<div onactivate="event.cancelBubble=true;" style="white-space:nowrap;">
<input name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue" type="text" size="28" readonly="readonly" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_txtValue" title="Support Group report parameter" class="null"><input src="/sites/pa/reports/Reserved.ReportViewerWebPart.axd?OpType=Resource&amp;Version=11.0.5058.0&amp;Name=Microsoft.Reporting.WebForms.Icons.MultiValueSelect.gif" name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$ddDropDownButton" type="image" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_ddDropDownButton" alt="Select a value" title="Select a value" style="vertical-align:top;cursor:pointer;">
</div>