Set hidden checkbox with Capybara

I have a checkbox that I want to check. This button has confirm alert related and some other things.

enter image description here

 <label> <div class="check label-checked"> <span>Confirm</span> <i class="fa fa-square-o"></i> <input class="confirm-reservation-js" hidden="" name="actions_to[56]" type="checkbox" value="confirm"> </div> </label> 

# js.erb

 $(__s.bookings + ".confirm-reservation-js").click(function() { var input, form; if (confirm( "<%= I18n.t('.reservations.alert.action') %>" )) { form = $(__s.bookings + '[id^=edit_booking_]'); input = $("<input>") .attr("type", "hidden") .attr("name", "confirm").val("true"); form.append($(input)); form.submit(); } }); 

I can not check this button with Capybara. I have tried:

1- find(locator, visible: false).click

2- find(locator).trigger('click')

Where locator is the path to my input.

Additional

 # Gemfile gem 'capybara', '2.0.2' gem 'capybara-webkit', '~> 1.1.0' # Test file it "..." , js: true do 

Can anyone help me check this box?

Thanks.

+5
source share
1 answer

Capybara has an option (Capybara.ignore_hidden_elements) to configure default query behavior for finding nodes in the DOM. The default value is false. This means that your css or xpath requests will find all nodes in the document, regardless of their visibility on the page. You can overwrite this behavior for a single request by passing the parameter: visible => true | false

Change the default behavior of capybara ie

 Capybara.ignore_hidden_elements = true 

You can also follow the link: http://makandracards.com/makandra/7617-change-how-capybara-sees-or-ignores-hidden-elements :)

+2
source

Source: https://habr.com/ru/post/1206932/


All Articles