选择带有隐藏输入类型的复选框 [英] select checkbox with hidden input type

查看:23
本文介绍了选择带有隐藏输入类型的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位,

我正在使用 watir-webdriver,我的 HTML DOM 中有一个片段,当我输入一些凭据时,它会即时生成,这个片段有一堆复选框,复选框的数量各不相同,我必须选择一个复选框,下面是一个例子,在这里我想选择第二个复选框(输入类型隐藏的值为BS"但所有输入类型复选框的值都相同):

I am using watir-webdriver, I have a piece in my HTML DOM which gets generated on the fly when I enter some credentials, this piece has a bunch of checkboxes, the number of checkboxes vary, I have to select one checkbox, below is an example of this, here I want to select the second checkbox(the one that has value "BS" for the input type hidden but the value for input type checkbox is same for all):

   <li class="dir">
<input type="checkbox" value="1" onclick="$(this).next('.should_destroy').value = (this.checked?0:1)" name="should_not_destroy">
<input class="should_destroy" type="hidden" value="1" name="import[dir_attributes][][should_destroy]">
<input type="hidden" value="" name="import[dir_attributes][][id]">
<input type="hidden" value="Automation" name="import[dir_attributes][][path]">
<span class="dir_mode">Include</span>
Automation
</li>
<li class="dir">
<input type="checkbox" value="1" onclick="$(this).next('.should_destroy').value = (this.checked?0:1)" name="should_not_destroy">
<input class="should_destroy" type="hidden" value="1" name="import[dir_attributes][][should_destroy]">
<input type="hidden" value="" name="import[dir_attributes][][id]">
<input type="hidden" value="BS" name="import[dir_attributes][][path]">
<span class="dir_mode">Include</span>
BS
</li>

我也许可以用 XPATH 做到这一点,但想尝试一个非 XPATH 解决方案.输入类型 hidden 具有我需要的适当值,例如,在第二个复选框上方,输入类型隐藏的值为BS".我尝试使用这样的隐藏方法:

I may be able to do this with XPATH, but wanted to try a non XPATH solution. The input type hidden has the appropriate value that I need, for example above the second checkbox has value "BS" for input type hidden. I tried to use the hidden method like this:

h  = @@browser.hidden(:value, "BS")
h.select

但是我不知道在这之后该怎么办.我正在尝试根据隐藏元素的值选择复选框.非常感谢任何反馈.

But I dont know what to do after this. I am trying to select the checkbox based on the value of the hidden element. Any feedback is much appreciated.

推荐答案

我建议改用可见元素.我认为它更容易阅读测试并且看起来更稳定.

I would suggest using the visible elements instead. I think it makes it easier to read the test and seems more stable.

试试:

@@browser.li(:class => 'dir', :text => /BS/).checkbox.set

这篇关于选择带有隐藏输入类型的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆