Skip to content

Latest commit

 

History

History
117 lines (76 loc) · 2.38 KB

siblings.md

File metadata and controls

117 lines (76 loc) · 2.38 KB
title
siblings

Get sibling DOM elements.

Syntax

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

Usage

{% fa fa-check-circle green %} Correct Usage

cy.get('td').siblings()           // Yield all td's siblings
cy.get('li').siblings('.active')  // Yield all li's siblings with class '.active'

{% fa fa-exclamation-triangle red %} Incorrect Usage

cy.siblings('.error')     // Errors, cannot be chained off 'cy'
cy.location().siblings()  // Errors, 'location' does not yield DOM element

Arguments

{% 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 .siblings().

Option Default Description
log true {% usage_options log %}
timeout {% url defaultCommandTimeout configuration#Timeouts %} {% usage_options timeout .siblings %}

Yields {% helper_icon yields %}

{% yields changes_dom_subject_or_subjects .siblings %}

Examples

No Args

Get the siblings of each li

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

Selector

Get siblings of element with class active

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

Rules

Requirements {% helper_icon requirements %}

{% requirements dom .siblings %}

Assertions {% helper_icon assertions %}

{% assertions existence .siblings %}

Timeouts {% helper_icon timeout %}

{% timeouts existence .siblings %}

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:

{% imgTag /img/api/siblings/find-siblings-of-dom-elements-to-test.png "Command Log siblings" %}

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

{% imgTag /img/api/siblings/console-log-of-sibling-elements.png "Console Log siblings" %}

{% history %} {% url "< 0.3.3" changelog#0-3-3 %} | .siblings() command added {% endhistory %}

See also

  • {% url .prev() prev %}
  • {% url .next() next %}