Cucumber, capybara and selenium - Submitting a form without a button

Daniel Cukier picture Daniel Cukier · May 9, 2010 · Viewed 16.1k times · Source

I have a test using Cucumber, capybara and selenium driver. This test should go to a form and submit it. The normal text would be

  Scenario: Fill form
    Given I am on the Form page
    When I fill in "field1" with "value1"
    And I fill in "field2" with "value2"
    And I press "OK"
    Then I should see "Form submited"

The problem is that I don't have the OK button in the form I need a way to do the "form.submit", without clicking any button or link - the same as happens when you press ENTER when you are in a form field using the browser.

I don't know how to tell capybara to submit a form. How can I do it?

Answer

Brian Dunn picture Brian Dunn · Mar 29, 2011

You can access the selenium send_keys method to invoke a return event like

 find_field('field2').native.send_key(:enter)