find() locates it on screen. Then act on it:
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 onfind() without awaiting it first:
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:
found():
ElementNotFoundError is exported from testdriverai:
Examples
Wait for something slow to appear
Make the match stricter
Useconfidence 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 fixedcacheKey:
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, ortype. - You can’t chain an action onto it. Pick an element from the array first.
Complete example
tests/login.test.mjs
Related
- Locate elements: write descriptions that match reliably
- click() and hover(): act on what you found
- Caching: how element positions are reused
- Element not found example: handle a missing element

