Skip to main content
This test looks for an element that isn’t on the page. Use this pattern when an element may not appear.

Watch it run

The test

element-not-found.test.mjs

How it works

  • By default, find() checks the screen every 5 seconds for up to 10 seconds.
  • When nothing matches, find() doesn’t throw.
  • Instead, it returns an element whose found() is false and whose coordinates are null.
  • Calling click() on an unfound element throws an ElementNotFoundError.

Run it

The test is in the TestDriver SDK repository. Clone it, install dependencies, and run the file:
The test reads your API key from TD_API_KEY. Create a key at console.testdriver.ai/team/api-keys. Then set it in your environment or a .env file.