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

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


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

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


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.


I just had to solve this problem myself. In webrat I had something like this:

Then /^I submit the "([^\"]*)" form$/ do |form_id|  submit_form form_idend

I was able to achieve the same thing with this in Capybara:

  Then /^I submit the "([^\"]*)" form$/ do |form_id|    element = find_by_id(form_id)    Capybara::RackTest::Form.new(page.driver, element.native).submit :name => nil  end