简体   繁体   中英

set checkbox using watir

<div class="icheckbox_minimal" style="position: relative;">
 <input class="checkbox" type="checkbox" value="1" name="order[terms]" 
  id="order_terms" style="position: absolute; top: -20%; left: -20%; 
  display: block; width: 140%; height: 140%; margin: 0px; padding: 0px;     
  background: rgb(255, 255, 255); border: 0px; opacity: 0;">
 <ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; 
  display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; 
  background: rgb(255, 255, 255); border: 0px; opacity: 0;">
 </ins>
</div>

How can I set the checkbox for this element?

I tried the following

browser.checkbox(:class => "iCheck-helper").when_present.set

browser.div(:class => "icheckbox_minimal").fire_event :click

you can click on ins tag to set the check box value as given below.

if !browser.checkbox(id: 'order_terms').set? then
   puts "not set"
   browser.element(class: 'iCheck-helper').click
end
puts browser.checkbox(id: 'order_terms').set? 

Try this

 browser.checkbox(id: "order_terms").set

When you locate an element, that element has to be checkbox when you use the method checkbox but you are passing the locator of div to checkbox method.

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