Javascript 在列表框边缘浏览器ruby selenium webdriver中选择多个选项
我的应用程序需要从microsoft edge browser的列表框中选择多个项目 我正在使用watir webdriver测试我的应用程序 DOM结构如下所示:Javascript 在列表框边缘浏览器ruby selenium webdriver中选择多个选项,javascript,ruby,selenium-webdriver,watir,microsoft-edge,Javascript,Ruby,Selenium Webdriver,Watir,Microsoft Edge,我的应用程序需要从microsoft edge browser的列表框中选择多个项目 我正在使用watir webdriver测试我的应用程序 DOM结构如下所示: <div id="textSearch"> <div id="textSearch"> <select name="@Type" id="textType" onchange="unselectOptionZero('@Type');" size="7" multiple="" width="250"&
<div id="textSearch">
<div id="textSearch">
<select name="@Type" id="textType" onchange="unselectOptionZero('@Type');" size="7" multiple="" width="250">
<option value="*" selected="">- All -</option>
<option value="text1">text1</option>
<option value="text2">text2</option>
<option value="text3">text3</option>
<option value="text4">text4</option>
<option value="text5">text5</option>
</select>
</div>
</div>
这似乎不起作用。我尝试通过.select使用迭代,但它似乎不起作用
我还尝试了selenium支持selenium::WebDriver::support::Select.new,但没有帮助。是否有其他方法可以使用javascript在microsoft edge browser中使用执行脚本选择多个选项。Watir的select\select
通过调用\click
方法选择选项。与其他驱动程序不同,Edge将此视为常规单击,取消选择前面的选项。这是Microsoft Edge团队的一项研究
他们的建议是使用Actions对象按住控制按钮。但是,如果尝试执行此操作,例如调用选项。单击(:control)
,将导致未知命令异常。边缘驱动程序已经完成
在此之前,您需要执行JavaScript来选择选项
如果您使用的是Watir v6.8或更高版本,则可以使用新的#选择代码>方法,通过JavaScript而不是鼠标单击来选择选项。这将保留以前选择的值
s= @browser.select_list(:id, "textType")
s.select!("text3")
s.select!("text4")
请注意,#select
现在支持按文本和值查找选项(与以前只选中文本的版本相反)
如果您使用的是Watir的早期版本,则可以使用#execute_script
:
s= @browser.select_list(:id, "textType")
select_script = 'arguments[0].selected=true;'
@browser.execute_script(select_script, s.option(:value => "text3"))
@browser.execute_script(select_script, s.option(:value => "text4"))
谢谢你的帮助
s= @browser.select_list(:id, "textType")
select_script = 'arguments[0].selected=true;'
@browser.execute_script(select_script, s.option(:value => "text3"))
@browser.execute_script(select_script, s.option(:value => "text4"))