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