Files
cypress/docs/source/api/commands/submit.md
2017-05-31 12:15:28 -04:00

1.7 KiB

title, comments, description
title comments description
submit true

Submit a form.

Syntax

.submit()
.submit(options)

Usage

.submit() requires being chained off another cy command that yields a form.

{% fa fa-check-circle green %} Valid Usage

cy.get('form').submit() // Submit a form

{% fa fa-exclamation-triangle red %} Invalid Usage

cy.submit()               // Errors, cannot be chained off 'cy'
cy.get('input').submit()  // Errors, 'input' does not yield a form

Arguments

{% fa fa-angle-right %} options (Object)

Pass in an options object to change the default behavior of .submit().

Yields

.submit() yields the form that was submitted.

Timeout

.submit() will continue to try to submit the form for the duration of the defaultCommandTimeout

Example

Submit a form

Submit can only be called on a single form.

<form id="contact">
  <input type="text" name="message">
  <button type="submit">Send</button>
</form>
cy.get('#contact').submit()

Command Log

Submit a form

cy.route('POST', '/users', 'fixture:user').as('userSuccess')
cy.get('form').submit()

The commands above will display in the command log as:

screen shot 2015-11-29 at 1 21 43 pm

When clicking on submit within the command log, the console outputs the following:

cy.submit console log

See also