Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.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
Javascript 如何在Python 3中使用selenium在javascrip站点中选择下拉列表?_Javascript_Python_Python 3.x_Selenium - Fatal编程技术网

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

Javascript 如何在Python 3中使用selenium在javascrip站点中选择下拉列表?,javascript,python,python-3.x,selenium,Javascript,Python,Python 3.x,Selenium,我被困在下面的html代码中,这些代码取自一个使用Javascript的网站。我想要的是使用select moduele在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',

我被困在下面的html代码中,这些代码取自一个使用Javascript的网站。我想要的是使用select moduele在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;">
这会产生以下错误:

raise UnexpectedTagNameException(
selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on <select> elements, not on <input>
raiseunexpectedtagname异常(
selenium.common.exceptions.UnexpectedTagNameException:消息:选择仅适用于元素,不适用于

您只需使用
send_keys()
功能在下拉列表中选择特定选项。

  • 首先通过任何
    find_element()
    函数找到下拉列表的元素
  • 在该元素上使用
    send_keys()
    函数立即从列表中选择任何值
  • 简言之,按以下方式进行应该可以完成您需要的工作:

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

    您的xpath出现了一些错误。可能是您选择了错误元素的xpath。请共享站点链接,以便我可以帮助您。看起来您使用的是输入标签,而不是下拉标签。这对我很有效,谢谢您的帮助,请接受它作为答案。
    driver.find_element_by_id('WD51').send_keys('Short_Budget_Report')