Files
cypress/docs/source/api/commands/root.md
T
2017-05-19 12:01:36 -04:00

1.4 KiB

title, comments, description
title comments description
root true

Get the root element. By default the root is document. When calling cy.root in a cy.within, the root element will be the return of the within command.

Returns the new DOM element(s) found by the command.
Timeout cy.root will retry for the duration of the defaultCommandTimeout

cy.root()

Get the root element.

Options

Pass in an options object to change the default behavior of cy.root.

cy.root( options )

Option Default Notes
log true whether to display command in command log

Usage

Get the root element

// returns document
cy.root()

Get the root element in a within scope

<form>
  <input name="email" type="email">
  <input name="password" type="password">
  <button type="submit">Login</button>
</form>
cy.get("form").within(function(){
  cy
    .get("input[name='email']").type("john.doe@email.com")
    .get("input[name='password']").type("password")

    // the root element in a within is the previous
    // commands subject, in this case <form>
    .root().submit()
})

Related