Cucumber, Capybara and Selenium - Submitting a Form Without a Button

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)

Capybara - Submit a form without button

Although it's possible to achieve what you want using capybara, the easier and more practical solution is to put a submit button on the form.

There is no reason to not have a button on the form, it's bad accessibility to not have a form and users that do not have a GUI or are using screen readers will have trouble submitting the form otherwise.

If you don't want the form button to be visible, can I suggest using some CSS to make it hidden:

<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;">

Cucumber and Capybara, clicking a non-link or button element

You can click on an element via Capybara::Element.click. I add the following for this in my web_steps.rb to click on divs.

When /^(?:|I )click within "([^"]*)"$/ do |selector|
find(selector).click
end

There is also Element.trigger('mouseover') which appears to enable hover albeit not working with Selenium.

It is also very likely you will need to decorate your feature/scenario with Capybara's provided @javascript tag.

Nothing happens when pressing button in cucumber, capybara test before adding sleep

This could happen if the button is rendered in the DOM before the click event handler is bound. Capybara will be able to find the element as soon as it's in the DOM.

If this is the case, the tests are actually showing you that there is a (minor) bug. A real end user that clicked the button while the page is still loading would see the same result. A cleaner option would be to render the button via JavaScript and bind the click handler at the same time.

If changing the page isn't an option for you, there may still be hope. If there is something else on the page that is rendered by JavaScript in the same iteration of the event loop, you could add something to the test that looks for that before trying to click the button. For example, in the app I work on at my day job, we render an animated spinner GIF on the page when it loads, and then hide in in JavaScript when the page is fully loaded. Our Capybara tests wait for the spinner GIF to be hidden before interacting with the page.

Rails, Cucumber, Capybara - Cucumber step cannot press a button

can you tell me what is item in following code ? I guess it should be Quote

Scenario: Create a complete manual entered quote for a client
When I select the XXX as YYY
And I save the Item
Then I should see "Item was successfully created"

Capybara/Cucumber/Ruby issue: Press element only if appears and continue without errors

Rather than using find or expects you should be using Capybaras has_xxx? and has_no_xxx? methods (has_css?, has_button?, has_select?, ...) which return boolean results rather than raising expectations. In your case it would be

if page.has_css?('#idOfOneElement', wait: 2) 
page.find_by_id("idOfOneElement").click
end

Capybara prevents attaching onsubmit event to form

Since you're using Selenium - the most common reason would be that you have an error in one of your JS assets. When in the dev environment all your JS assets are served in separate files which means an error in one file doesn't stop others from being processed. In the test environment (and production) the assets are concatenated into one file which means an error in any file can cause assets concatenated after it to not be processed.

Check the browsers console log for any JS errors and fix them.



Related Topics



Leave a reply



Submit