Files
cypress/docs/source/api/commands/find.md

2.2 KiB

title, comments, description
title comments description
find true

Get the descendent DOM elements of a specific selector.

Syntax

.find(selector)
.find(selector, options)

Usage

.find() requires being chained off another cy command that yields a DOM element or DOM elements.

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

cy.get('.article').find('footer') // Yields 'footer' within '.article'

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

cy.find('.progress')          // Errors, cannot be chained off 'cy'
cy.exec('node start').find()  // Errors, 'exec' does not yield DOM element

Arguments

{% fa fa-angle-right %} selector (String selector)

A selector used to filter matching descendent DOM elements.

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

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

Option Default Notes
log true whether to display command in command log
timeout defaultCommandTimeout Total time to retry getting the element(s)

Yields

.find() yields the new DOM elements found by the command.

Timeout

.find() will continue to look for the filtered element(s) for the duration of the defaultCommandTimeout

Examples

Selector

Get li's within parent

<ul id="parent">
  <li class="first"></li>
  <li class="second"></li>
</ul>
// returns [<li class="first"></li>, <li class="second"></li>]
cy.get('#parent').find('li')

Command Log

Find the li's within the nav

cy.get('.left-nav>.nav').find('>li')

The commands above will display in the command log as:

screen shot 2015-11-27 at 2 19 38 pm

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

screen shot 2015-11-27 at 2 19 54 pm

See also