Files
cypress/docs/source/api/commands/siblings.md
T
2017-05-19 12:01:36 -04:00

2.1 KiB

title, comments, description
title comments description
siblings true

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

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

cy.siblings()

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

cy.siblings( selector )

Get the siblings of each DOM element in the set of matched DOM elements filtered by a selector.

Options

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

cy.siblings( options ) cy.siblings( selector, options )

Option Default Notes
log true whether to display command in command log
timeout defaultCommandTimeout Total time to retry getting the element

Usage

Get the siblings of each li.

<ul>
  <li>Home</li>
  <li>Contact</li>
  <li class="active">Services</li>
  <li>Price</li>
</ul>
// returns all other li's in list
cy.get(".active").siblings()

Selector Usage

Get siblings of element with class active.

// returns <li class="active">Services</li>
cy.get("li").siblings(".active")

Command Log

Get the siblings of element with class active

cy.get(".left-nav").find("li.active").siblings()

The commands above will display in the command log as:

screen shot 2015-11-29 at 12 48 55 pm

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

screen shot 2015-11-29 at 12 49 09 pm

Related