[英]How to assert whether a radio button is checked or not using Watir and Ruby?
Let's assume I have the following HTML: 假设我有以下HTML:
<form id='someForm'>
<input type='radio' name='someName' value='option-1' />
<input type='radio' name='someName' value='option-2' />
<input type='radio' name='someName' value='option-3' checked='checked' />
<input type='radio' name='someName' value='option-4' />
</form>
How can I use the watir-webdriver to assert that the 3rd option is checked? 如何使用watir-webdriver断言是否选中了第3个选项? I can't seem to find anything online.
我似乎无法在网上找到任何东西。 I would imagine it's something like...
我想这就像...
browser.input(:name => 'someName', :value => 'option-3').isChecked?
If any Watir experts could shine light on this that would be much appreciated. 如果有任何Watir专家对此有所启发,将不胜感激。
You can use the set?
可以用
set?
or checked?
或
checked?
method: 方法:
browser.radio(:name => 'someName', :value => 'option-3').checked?
or 要么
browser.radio(:name => 'someName', :value => 'option-3').set?
Since the element is a radio button, it is more clear if you use the radio
instead of input
method. 由于该元素是一个单选按钮,因此如果您使用
radio
而不是input
法,则将更加清楚。
U can check/unchecked the radio button using 'set' and 'clear' methods .Inorder to check whether the radiobutton is already checked or not just add '?' U可以使用'set'和'clear'方法检查/取消选中单选按钮。为了检查单选按钮是否已被选中,只需添加'?' to the 'set' and 'checked' method 'set?'
到“设置”和“选中”方法“设置?” and 'checked?'
和“已检查?” which returns boolean value(true/false)
返回布尔值(真/假)
browser.radio(:name => 'someName', :value => 'option-3').set?
browser.radio(:name => 'someName', :value => 'option-3').checked?
so here the method set?,checked? 所以这里方法设置了吗? returns the boolean value.
返回布尔值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.