Files
cypress/docs/source/api/commands/parentsuntil.md
T

2.7 KiB

title, comments, description
title comments description
parentsuntil true

Get all ancestors of each DOM element in the set of matched DOM elements up to, but not including, the element matched by the selector

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

cy.parentsUntil( selector )

Get all of the ancestors of the elements until the selector.

cy.parentsUntil( selector, *filter )

When a filter is provided, it retrieves all of the ancestors up until the selector only if it matches that filter.

cy.parentsUntil( element )

Get all of the ancestors of the elements until the DOM node or jQuery object.

cy.parentsUntil( element, *filter )

When a filter is provided, it retrieves all of the ancestors up until the DOM node or jQuery object only if it matches that filter.

Options

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

cy.parentsUntil( selector, options ) cy.parentsUntil( selector, filter, options ) cy.parentsUntil( element, options ) cy.parentsUntil( element, filter, options )

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

Usage

Find all of the .active element's ancestors until .nav

<ul class="nav">
  <li>
    <a href="#">Clothes</a>
    <ul class="menu">
      <li>
        <a href="/shirts">Shirts</a>
      </li>
      <li class="active">
        <a href="/pants">Pants</a>
      </li>
    </ul>
  </li>
</ul>
//returns [ul.menu, li]
cy.get(".active").parentsUntil(".nav")

Command Log

Find all of the .active element's ancestors until .nav

cy.get(".active").parentsUntil(".nav")

The commands above will display in the command log as:

screen shot 2017-03-23 at 2 37 31 pm

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

screen shot 2017-03-23 at 2 37 39 pm

Related