mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
1.9 KiB
1.9 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| parent | true |
Get the parent DOM element of the DOM elements.
| Returns | the new DOM element(s) found by the command. |
| Timeout | cy.parent will retry for the duration of the defaultCommandTimeout |
cy.parent()
Get the parent of each element in the current set of matched elements.
cy.parent( selector )
Get the parent of each element in the current set of matched elements filtered by selector.
Options
Pass in an options object to change the default behavior of cy.parent.
cy.parent( options ) cy.parent( selector, options )
| Option | Default | Notes |
|---|---|---|
log |
true |
whether to display command in command log |
timeout |
defaultCommandTimeout |
Total time to retry getting the element |
Usage
Get the parent of the active li
cy.get("li.active").parent()
Selector Usage
Get the parent with class nav of the active li
cy.get("li.active").parent(".nav")
Command Log
Assert on the parent of the active li
cy.get("li.active").parent().should("have.class", "nav")
The commands above will display in the command log as:
When clicking on the parent command within the command log, the console outputs the following: