mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-21 22:50:49 -06:00
2.3 KiB
2.3 KiB
title: prevall comments: true
Get all previous siblings of each DOM element in the set of matched DOM elements.
| Returns | the new DOM element(s) found by the command. |
| Timeout | cy.prevAll will retry for the duration of the defaultCommandTimeout |
cy.prevAll()
Get all of the next siblings of the elements.
cy.prevAll( selector )
When a selector is provided, it retrieves all of the previous siblings only if it matches that selector.
Options
Pass in an options object to change the default behavior of cy.prevAll.
cy.prevAll( options ) cy.prevAll( selector, options )
| Option | Default | Notes |
|---|---|---|
log |
true |
whether to display command in command log |
timeout |
defaultCommandTimeout |
Total time to retry getting the element |
Usage
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>
//returns [<li>apples</li>, <li>oranges</li>]
cy.get(".third").prevAll()
Selector Usage
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>
//returns <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:
When clicking on prevAll within the command log, the console outputs the following: