2.5 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| siblings | true |
Get sibling DOM elements.
Syntax
.siblings()
.siblings(selector)
.siblings(options)
.siblings(selector, options)
Usage
.siblings() requires being chained off another cy command that yields a DOM element or DOM elements.
{% fa fa-check-circle green %} Valid 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 %} Invalid 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 | Notes |
|---|---|---|
log |
true |
whether to display command in command log |
timeout |
defaultCommandTimeout |
Total time to retry getting the element |
Yields
.siblings() yields the new DOM elements found by the command.
Timeout
.siblings() will continue to look for the sibling element(s) for the duration of the defaultCommandTimeout
Examples
Siblings
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')
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:
When clicking on siblings within the command log, the console outputs the following: