2.3 KiB
title, comments
| title | comments |
|---|---|
| next | false |
Get the immediately following sibling of each DOM element within a set of DOM elements.
Syntax
.next()
.next(selector)
.next(options)
.next(selector, options)
Usage
{% fa fa-check-circle green %} Correct Usage
cy.get('nav a:first').next() // Yield next link in nav
{% fa fa-exclamation-triangle red %} Incorrect Usage
cy.next() // Errors, cannot be chained off 'cy'
cy.getCookies().next() // 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 .next().
| Option | Default | Description |
|---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .next %} |
Yields {% helper_icon yields %}
{% yields changes_dom_subject .next %}
Examples
Next
Find the element next to .second
<ul>
<li>apples</li>
<li class="second">oranges</li>
<li>bananas</li>
</ul>
// yields <li>bananas</li>
cy.get('.second').next()
Selector
Find the very next sibling 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>
</ul>
// yields <li>pineapples</li>
cy.get('li').next('.selected')
Rules
Requirements {% helper_icon requirements %}
{% requirements dom .next %}
Assertions {% helper_icon assertions %}
{% assertions existence .next %}
Timeouts {% helper_icon timeout %}
{% timeouts existence .next %}
Command Log
Find the element next to the .active li
cy.get('.left-nav').find('li.active').next()
The commands above will display in the command log as:
When clicking on next within the command log, the console outputs the following:
See also
- {% url
.nextAll()nextall %} - {% url
.nextUntil()nextuntil %} - {% url
.prev()prev %}

