title |
---|
prev |
Get the immediately preceding sibling of each element in a set of the elements.
{% note info %}
The querying behavior of this command matches exactly how {% url .prev()
http://api.jquery.com/prev %} works in jQuery.
{% endnote %}
.prev()
.prev(selector)
.prev(options)
.prev(selector, options)
{% fa fa-check-circle green %} Correct Usage
cy.get('tr.highlight').prev() // Yield previous 'tr'
{% fa fa-exclamation-triangle red %} Incorrect Usage
cy.prev() // Errors, cannot be chained off 'cy'
cy.getCookies().prev() // Errors, 'getCookies' does not yield DOM element
{% 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 .prev()
.
Option | Default | Description |
---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .prev %} |
{% yields changes_dom_subject_or_subjects .prev %}
<ul>
<li>Cockatiels</li>
<li>Lorikeets</li>
<li class="active">Cockatoos</li>
<li>Conures</li>
<li>Eclectus</li>
</ul>
// yields <li>Lorikeets</li>
cy.get('.active').prev()
<ul>
<li>Cockatiels</li>
<li>Lorikeets</li>
<li class="active">Cockatoos</li>
<li>Conures</li>
<li>Eclectus</li>
</ul>
// yields <li>Cockatoos</li>
cy.get('li').prev('.active')
{% requirements dom .prev %}
{% assertions existence .prev %}
{% timeouts existence .prev %}
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:
{% imgTag /img/api/prev/find-prev-element-in-list-of-els.png "Command Log prev" %}
When clicking on prev
within the command log, the console outputs the following:
{% imgTag /img/api/prev/previous-element-in-console-log.png "Console Log prev" %}
- {% url
.next()
next %} - {% url
.prevAll()
prevall %} - {% url
.prevUntil()
prevuntil %}