| title | next |
|---|
Get the immediately following sibling of each DOM element within a set of DOM elements.
{% note info %}
The querying behavior of this command matches exactly how {% url .next() http://api.jquery.com/next %} works in jQuery.
{% endnote %}
.next()
.next(selector)
.next(options)
.next(selector, options){% 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{% 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 changes_dom_subject_or_subjects .next %}
<ul>
<li>apples</li>
<li class="second">oranges</li>
<li>bananas</li>
</ul>// yields <li>bananas</li>
cy.get('.second').next()<input list="fruit" />
<datalist id="fruit">
<option>Apple</option>
<option>Banana</option>
<option>Cantaloupe</option>
</datalist>cy.get('#fruit option')
.first().should('have.text', 'Apple')
.next().should('have.text', 'Banana')
.next().should('have.text', 'Cantaloupe')<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'){% requirements dom .next %}
{% assertions existence .next %}
{% timeouts existence .next %}
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:
{% imgTag /img/api/next/find-next-element-when-testing-dom.png "Command Log next" %}
When clicking on next within the command log, the console outputs the following:
{% imgTag /img/api/next/elements-next-command-applied-to.png "Console Log next" %}
- {% url
.nextAll()nextall %} - {% url
.nextUntil()nextuntil %} - {% url
.prev()prev %}