5

I've got a checkbox that I want to check. This button has a confirm alertassociated and some other stuff.

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 cannot check this button with Capybara. I was trying with:

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

Somebody can help me to check this checkbox please?

Thanks.

Community
  • 1
  • 1
edudepetris
  • 714
  • 14
  • 27
  • Have you tried `find(:css, "#your-css-selecter").set(true)`? – jmera Nov 15 '14 at 05:21
  • I get the same error that the example 1. `Capybara::Webkit::ClickFailed: Failed to find position for element /html/.../input because it is not visible` – edudepetris Nov 15 '14 at 12:27
  • Check out [this](http://www.elabs.se/blog/60-introducing-capybara-2-1) post (under visibility). It might shed some light. It seems like you're using Capybara 2.0.2, where by default, `Capybara.ignore_hidden_elements = false`. So, unless you've modified that config, Capybara should be picking that element up. Try using the `visible: false` or `hidden: true` options to see if that works. I haven't tested it out myself but I think it's worth a try. – jmera Nov 17 '14 at 12:05

1 Answers1

2

Capybara has an option (Capybara.ignore_hidden_elements) to configure the default query behavior of finding nodes within the DOM. It's default value is false. That means that your css or xpath queries will find all nodes in the document regardless of their visibility on the page. You can overwrite this behavior for an individual query by passing the :visible => true|false option.

Change the default behavior of capybara i.e.

Capybara.ignore_hidden_elements = true

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

Rahul
  • 229
  • 2
  • 6