Files
cypress/docs/source/api/commands/parent.md
T
2017-05-23 17:17:27 -04:00

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:

screen shot 2015-11-27 at 1 58 32 pm

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

screen shot 2015-11-27 at 1 58 44 pm

See also