title |
---|
siblings |
Get sibling DOM elements.
.siblings()
.siblings(selector)
.siblings(options)
.siblings(selector, options)
Correct Usage
cy.get('td').siblings() // Yield all td's siblings
cy.get('li').siblings('.active') // Yield all li's siblings with class '.active'
Incorrect Usage
cy.siblings('.error') // Errors, cannot be chained off 'cy'
cy.location().siblings() // Errors, 'location' does not yield DOM element
selector (String selector)
A selector used to filter matching DOM elements.
options (Object)
Pass in an options object to change the default behavior of .siblings()
.
Option | Default | Description |
---|---|---|
log |
true |
Displays the command in the Command log |
timeout |
defaultCommandTimeout |
Time to wait for .siblings() to resolve before timing out |
.siblings()
yields the new DOM element(s) it found.<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')
.siblings()
requires being chained off a command that yields DOM element(s)..siblings()
will automatically retry until the element(s) exist in the DOM.siblings()
will automatically retry until all chained assertions have passed.siblings()
can time out waiting for the element(s) to exist in the DOM..siblings()
can time out waiting for assertions you've added to pass.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:
Version | Changes |
---|---|
< 0.3.3 | .siblings() command added |