mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
1.2 KiB
1.2 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| root | true |
Get the root element.
| 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()
})