【发布时间】:2021-07-17 13:56:31
【问题描述】:
我被困在以下 html 代码中,该代码取自一个使用 Javascript 的站点。我想要的是使用 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>
【问题讨论】:
-
有一些与您的 xpath 相关的错误。可能是您选择了错误元素的 xpath。请分享网站链接,以便我可以帮助您
-
您似乎在输入标签而不是下拉菜单
标签: javascript python python-3.x selenium