Improve this doc

Get all ancestors of each DOM element in a set of matched DOM elements up to, but not including, the element provided.

The querying behavior of this command matches exactly how .parentsUntil() works in jQuery.


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


Correct Usage

cy.get('p').parentsUntil('.article') // Yield parents of 'p' until '.article'

Incorrect Usage

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


selector (String selector)

The selector where you want finding parent ancestors to stop.

element (DOM node, jQuery Object)

The element where you want finding parent ancestors to stop.

filter (String selector)

A selector used to filter matching DOM elements.

options (Object)

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

Option Default Description
log true Displays the command in the Command log
timeout defaultCommandTimeout Time to wait for .parentsUntil() to resolve before timing out


  • .parentsUntil() yields the new DOM element(s) it found.



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

<ul class="nav">
    <a href="#">Clothes</a>
    <ul class="menu">
        <a href="/shirts">Shirts</a>
      <li class="active">
        <a href="/pants">Pants</a>
// yields [, li]



  • .parentsUntil() requires being chained off a command that yields DOM element(s).


  • .parentsUntil() will automatically retry until the element(s) exist in the DOM.

  • .parentsUntil() will automatically retry until assertions you've chained all pass.


  • .parentsUntil() can time out waiting for the element(s) to exist in the DOM.

  • .parentsUntil() can time out waiting for assertions you've added to pass.

Command Log

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


The commands above will display in the Command Log as:

Command Log parentsUntil

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

Console Log parentsUntil

See also