我是Selenium的初学者,我想选择下拉列表的选项。但它始终不能处理错误消息" selenium.common.exceptions.ElementNotInteractableException:消息:"
HTML代码位于
之下<div id="template-select-dialog" class="modal fade in" tabindex="-1" data-keyboard="true" style="display: block;" aria-hidden="false" hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="modal-body">
<div class="modal-body-title">
<div class="modal-body-message">
<div class="template-names">
<select id="template-select-dialog_template-names">
<option class="select-none"></option>
<option value="Sample server">Sample server</option>
<option value="Sample network">Sample network</option>
<option value="Sample server in network">Sample server in network</option>
<option value="KST stack">KST stack</option>
<option value="KST stack for LRT">KST stack for LRT</option>
</select>
我的硒代码在
下面dropM = browser.find_element_by_id("template-select-dialog_template-names")
dropM.find_element_by_xpath("//option[@value='KST stack for LRT']").click()
我不知道是否是&#34;隐藏=#&34;真&#34; &#34;或不,所以你能给我一些建议,谢谢!
答案 0 :(得分:1)
处理下拉选择元素有一个特殊的类
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_id("template-select-dialog_template-names"))
select.select_by_visible_text('KST stack for LRT')
更多信息在这里 - http://selenium-python.readthedocs.io/navigating.html#filling-in-forms