Cucumber and Capybara , How to Submit a Form Without a Button


Sometimes We run into  a problem where we need to submit a form after entering data but there is no specific button or link available on which we can perform operation to submit the form.so I am going to suggest few solutions today for these situations in few different ways so that any one can use the solution depending on his specific situation.


Where we can hit "Enter" to submit the form:

We can access the selenium send_keys method to invoke a return event like
 find_field('field2').native.send_key(:enter)

 Using  java script:

 When /^I submit the form$/ do
  page.evaluate_script("document.forms[0].submit()")
end

 Without Using java Script:

     we can handle this directly using Racktest(Capybara's default driver)
  When /^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

Where we cannot hit "Enter" to submit :


  We can click on an element via Capybara::Element.click.  by adding the following code   to click on the divs.
 When /^(?:|I )click within "([^"]*)"$/ do |selector|
  find(selector).click
end






Comments

Popular posts from this blog

Testing Webservice with SoapUI Having Windows Authentication

How to Uncheck All checkboxes Using Cucumber/Capybara