Core API

until()

Pause execution until a specific condition or element existence.

until()

Stop the execution until the target condition or element becomes available in the document.

Use Cases

  • Waiting for a modal to open: Trying to click a "Confirm" button inside a dialog only after the API has successfully loaded it.
  • Form completion check: Delaying the submission click until all required fields are validated and filled.

Example

const cursor = new Cursor();

cursor
  .click('#fetch-data')
  // Wait until `.result-item` is added to the DOM dynamically
  .until('.result-item', (ctx) => {
      // Callback executed only once `.result-item` is visible 
      ctx.hover('.result-item').click('.result-item');
  });

You can also pass a custom function as the condition:

const cursor = new Cursor();

cursor
  .until(
    () => window.isDataLoaded === true,
    (ctx) => ctx.click('.submit-btn')
  );

On this page