Cypress nextUntil Command

Profile picture for user arilio666

nextUntil command in cypress fetches all the following immediate sibling DOM elements up to but not including the one specified.


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

Arguments Used In nextUntil:

  1. Selector: This is an argument used in the nextUntil command to find up to the needed element and stop.
  2. Filter: A selector is used to filter matching DOM elements.
  3. Element: The element where you want finding the following siblings to stop.
  4. Options: Argument used to pass in an object to change the default behavior of nextUntil().
    • Log: Displays the command in the command log, and the default value is actual.
    • Timeout: Time to wait till the following command resolves before timing out.

Correct Usage Of nextUntil:

  • yields all siblings next of 'nav' up to and before #pass

Wrong Usage Of nextUntil:

  • It cannot be chained off with cy.


  • For a real-time example, we will try to automate our traditional programsbuzz login page.
  • We will fetch the DOM elements of the login page using the nextUntil command of cypress.
  • Password and up to login button will be used to fetch the password type field and the below text when nextUntil is used.

Cypress next until

describe('Automate PB',()=>{







cypress next until

  • We can see here that we first provided the password text field and in the nextUntil supplied with the login selector.
  • So, according to that, it left off the login selector and yielded the one next to the password text, which is the password type field and the text below it.

Rules For Using NextUntil:

  • nextUntil yields the DOM element it has yielded currently.
  • nextUntil requires it to be chained off a command that delivers DOM elements.
  • nextUntil assertions will automatically retry until the elements exist in DOM.
  • nextUntil can timeout waiting for the elements to live in the DOM.