简体   繁体   中英

Ruby Watir radio checkbox

im trying to set the checkbox on a radio control with the .set? option. it returns false but I'm unable to set the checkbox.

<div class="">
<input name="radiostorage" id="zrs" value="2" type="radio">
<label for="zrs">Zone-redundant storage (ZRS)</label>
</div>

have tried with label(for: 'zrs').set .click .parent.click .parent.set, also directly trying to click on the input , but nothing happens, any clue on that

TIA

Given the way that the radio button is implemented, it will not be considered visible. You will get an exception trying to set it directly:

browser.radio(id: 'zrs').set
#=> element located, but timed out after 2 seconds, waiting for #<Watir::Radio: located: true; {:id=>"zrs", :tag_name=>"input", :type=>"radio"}> to be present (Watir::Exception::UnknownObjectException)

Instead of setting it directly, you can click its associated label, which is what an actual user would do:

browser = Watir::Browser.new
browser.goto('https://pricing-calculator.bluekiri.cloud/')
p browser.radio(id: 'zrs').set?
#=> false
browser.label(for: 'zrs').click
p browser.radio(id: 'zrs').set?
#=> true

How about

radio = browser.radio(id: 'zrs')
radio.set?        #=> false
radio.set
radio.set?        #=> true

See http://www.rubydoc.info/gems/watir-webdriver/Watir/Radio

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM