Files
cypress/docs/source/api/commands/prevall.md
T
2017-05-26 16:10:23 -04:00

2.6 KiB

title, comments, description
title comments description
prevall true

Get all previous siblings of each DOM element in a set of matched DOM elements.

Syntax

.prevAll()
.prevAll(selector)
.prevAll(options)
.prevAll(selector, options)

Usage

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

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

cy.get('.active').prevAll() // Yield all links previous to `.active`

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

cy.prevAll()                // Errors, cannot be chained off 'cy'
cy.getCookies().prevAll()   // Errors, 'getCookies' does not yield DOM element

Arguments

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

A selector used to filter matching DOM elements.

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

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

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

Examples

All Previous

Find all of the element's siblings before .third

<ul>
  <li>apples</li>
  <li>oranges</li>
  <li class="third">bananas</li>
  <li>pineapples</li>
  <li>grapes</li>
</ul>
// yields [<li>apples</li>, <li>oranges</li>]
cy.get('.third').prevAll()

Selector

Find all of the previous siblings of each li. Keep only the ones with a class selected.

<ul>
  <li>apples</li>
  <li>oranges</li>
  <li>bananas</li>
  <li class="selected">pineapples</li>
  <li>grapes</li>
</ul>
// yields <li>pineapples</li>
cy.get('li').prevAll('.selected')

Command Log

Find all elements before the .active li

cy.get('.left-nav').find('li.active').prevAll()

The commands above will display in the command log as:

screen shot 2017-03-23 at 2 50 20 pm

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

screen shot 2017-03-23 at 2 50 26 pm

See also