Get all following siblings of each DOM element in a set of matched DOM elements.
The querying behavior of this command matches exactly how
.nextAll()works in jQuery.
.nextAll()
.nextAll(selector)
.nextAll(options)
.nextAll(selector, options)
Correct Usage
cy.get('.active').nextAll() // Yield all links next to `.active`
Incorrect Usage
cy.nextAll() // Errors, cannot be chained off 'cy'
cy.getCookies().nextAll() // Errors, 'getCookies' does not yield DOM element
selector (String selector)
A selector used to filter matching DOM elements.
options (Object)
Pass in an options object to change the default behavior of .nextAll().
| Option | Default | Description |
|---|---|---|
log |
true |
Displays the command in the Command log |
timeout |
defaultCommandTimeout |
Time to wait for .nextAll() to resolve before timing out
|
.nextAll() yields the new DOM element(s) it found. .second
<ul>
<li>apples</li>
<li class="second">oranges</li>
<li>bananas</li>
<li>pineapples</li>
<li>grapes</li>
</ul>
// yields [<li>bananas</li>, <li>pineapples</li>, <li>grapes</li>]
cy.get('.second').nextAll()
selected
<ul>
<li>apples</li>
<li>oranges</li>
<li>bananas</li>
<li class="selected">pineapples</li>
<li>grapes</li>
</ul>
// yields <li>pineapples</li>
cy.get('li').nextAll('.selected')
.nextAll() requires being chained off a command that yields DOM element(s). .nextAll() will automatically retry until the element(s) exist in the DOM .nextAll() will automatically retry until all chained assertions have passed .nextAll() can time out waiting for the element(s) to exist in the DOM . .nextAll() can time out waiting for assertions you've added to pass. Find all elements following the .active li
cy.get('.left-nav').find('li.active').nextAll()
The commands above will display in the Command Log as:
When clicking on nextAll within the command log, the console outputs the following:
© 2017 Cypress.io
Licensed under the MIT License.
https://docs.cypress.io/api/commands/nextall