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
Give
I'd recommend you add a submit button, then hide it with CSS. Then you can test the form submission, but still get the user behavior you want.
The display:none solution does not work with capybara using selenium driver because selenium complains about interacting with invisible elements. If you try the above solution you may end up seeing the following error message:
Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)
A simple solution:
When /^I submit the form$/ do
page.evaluate_script("document.forms[0].submit()")
end
Worked for me with capybara-envjs. Should work with selenium as well.
You can try sending a newline:
find_field('field2').native.send_key("\n")
You can access the selenium send_keys method to invoke a return event like
find_field('field2').native.send_key(:enter)
You may probably roll your own step (And I submit the form with the link "Ok", for example), and emulate the submit functionality yourself.
Here it is the javascript emulation dropped in Rails 3 to support "unobtrusive" (emphasis on the quotes) Javascript. The line
Capybara::Driver::RackTest::Form.new(driver, js_form(self[:href], emulated_method)).submit(self)
is probably the clue to answer your problem. The full code is here