mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
2.2 KiB
2.2 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| prev | true |
Get the immediately preceding sibling of each element in the set of the elements.
| Returns | the new DOM element(s) found by the command. |
| Timeout | cy.prev will retry for the duration of the defaultCommandTimeout |
cy.prev()
Get the immediately preceding sibling of each element in the set of matched elements.
cy.prev( selector )
Get the immediately preceding sibling of each element in the set of matched elements filtered by selector.
Options
Pass in an options object to change the default behavior of cy.prev.
cy.prev( options ) cy.prev( 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 the previous element of the element with class of active
<ul>
<li>Cockatiels</li>
<li>Lorikeets</li>
<li class="active">Cockatoos</li>
<li>Conures</li>
<li>Eclectus</li>
</ul>
// returns <li>Lorikeets</li>
cy.get('.active').prev()
Selector Usage
Find the previous element with a class of active
<ul>
<li>Cockatiels</li>
<li>Lorikeets</li>
<li class="active">Cockatoos</li>
<li>Conures</li>
<li>Eclectus</li>
</ul>
// returns <li>Cockatoos</li>
cy.get('li').prev('.active')
Command Log
Find the previous element of the active li
cy.get('.left-nav').find('li.active').prev()
The commands above will display in the command log as:
When clicking on prev within the command log, the console outputs the following: