Files
cypress/docs/source/api/commands/nextall.md
T

2.3 KiB

title, comments, description
title comments description
nextall true

Get all following siblings of each DOM element in the set of matched DOM elements.

Returns the new DOM element(s) found by the command.
Timeout cy.nextAll will retry for the duration of the defaultCommandTimeout

cy.nextAll()

Get all of the next siblings of the elements.

cy.nextAll( selector )

When a selector is provided, it retrieves all of the following siblings only if it matches that selector.

Options

Pass in an options object to change the default behavior of cy.nextAll.

cy.nextAll( options ) cy.nextAll( 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 all of the element's siblings following .second

<ul>
  <li>apples</li>
  <li class="second">oranges</li>
  <li>bananas</li>
  <li>pineapples</li>
  <li>grapes</li>
</ul>
//returns [<li>bananas</li>, <li>pineapples</li>, <li>grapes</li>]
cy.get(".second").nextAll()

Selector Usage

Find all of the following siblings 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>
  <li>grapes</li>
</ul>
//returns <li>pineapples</li>
cy.get("li").nextAll(".selected")

Command Log

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:

screen shot 2017-03-23 at 2 05 32 pm

When clicking on nextAll within the command log, the console outputs the following:

screen shot 2017-03-23 at 2 05 52 pm

Related