Skip to main content
Describe an element the way a person would, and find() locates it on screen. Then act on it:
For writing good descriptions, see Locate elements.

Signature

Parameters

string
required
What the element looks like and where it is, such as 'Add to cart button under the TestDriver Hat'.
object

Returns

ChainableElementPromise. It resolves to an Element, and you can also call an action on it directly (see Chain an action). The element has these methods and properties:

Chain an action

You can call an action on find() without awaiting it first:
These chain the same way: hover(), doubleClick(), rightClick(), mouseDown(), mouseUp(), and found().

When the element isn’t found

find() doesn’t throw when nothing matches. It returns an element whose found() is false and whose coordinates is null. Acting on that element throws an ElementNotFoundError, so a missing element still fails the test at the action:
To handle an element that may not be there, check found():
ElementNotFoundError is exported from testdriverai:

Examples

Wait for something slow to appear

Make the match stricter

Use confidence and verify where clicking the wrong element is costly:

Find a small target in a crowded screen

Disambiguate a short description

Keep the cache when the description changes

A description with a changing value never matches its cached entry. Give it a fixed cacheKey:

Tighten the cache for one call

findAll()

Locates every element that matches a description and returns them as an array.
string
required
What the elements look like, such as 'coffee cup icon'.
object
findAll() differs from find():
  • It checks the screen once. There’s no timeout.
  • It returns [] when nothing matches. It doesn’t throw.
  • It doesn’t support confidence, verify, zoom, or type.
  • You can’t chain an action onto it. Pick an element from the array first.
See the find all example for a complete test.

Complete example

tests/login.test.mjs