Let's assume I have the following 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? 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.
You can use the set?
or 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.
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 '?' 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.