Files
cypress/docs/source/api/commands/next.md
T
2017-05-23 17:17:27 -04:00

2.1 KiB

title, comments, description
title comments description
next true

Get the immediately following sibling of each DOM element in the set of matched DOM elements.

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

cy.next()

Get the next sibling of the elements.

cy.next( selector )

When a selector is provided, it retrieves the next sibling only if it matches that selector.

Options

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

cy.next( options ) cy.next( 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 the element next to .second

<ul>
  <li>apples</li>
  <li class="second">oranges</li>
  <li>bananas</li>
</ul>
//returns <li>bananas</li>
cy.get('.second').next()

Selector Usage

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>
//returns <li>pineapples</li>
cy.get('li').next('.selected')

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:

screen shot 2015-11-29 at 12 42 07 pm

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

screen shot 2015-11-29 at 12 42 22 pm

See also