简体   繁体   English

Ruby Watir单选复选框

[英]Ruby Watir radio checkbox

im trying to set the checkbox on a radio control with the .set? 我正在尝试使用.set设置无线电控件上的复选框? option. 选项。 it returns false but I'm unable to set the checkbox. 它返回false,但是我无法设置该复选框。

<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 已经尝试使用label(for:'zrs')。set .click .parent.click .parent.set,也直接尝试单击输入,但没有任何反应,任何提示

TIA 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 参见http://www.rubydoc.info/gems/watir-webdriver/Watir/Radio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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