title |
---|
siblings |
Get sibling DOM elements.
.siblings()
.siblings(selector)
.siblings(options)
.siblings(selector, options)
{% 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
{% 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 changes_dom_subject_or_subjects .siblings %}
<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()
// yields <li class="active">Services</li>
cy.get('li').siblings('.active')
{% requirements dom .siblings %}
{% assertions existence .siblings %}
{% timeouts existence .siblings %}
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 %}
- {% url
.prev()
prev %} - {% url
.next()
next %}