Skip to main content

Overview

Find UI elements on the screen with natural language descriptions and AI. This returns an Element object. You can interact with the object.

Syntax

Parameters

string
required
Natural language description of the element to find
object | number
Optional configuration for finding and caching

Returns

Promise<Element> - The Element instance that TestDriver found automatically.

Examples

Basic Element Finding

Finding with Context

Interacting with Found Elements

Element Object

The Element object that TestDriver returns gives these:

Methods

  • found() - Make a check if TestDriver found the element
  • click(action) - Click the element
  • hover() - Put the cursor on the element
  • doubleClick() - Double-click the element
  • rightClick() - Right-click the element
  • find(newDescription) - Find the element again with an optional new description

Properties

  • coordinates - Element position {x, y, centerX, centerY}
  • x, y - Top-left coordinates
  • centerX, centerY - Center coordinates
  • text - Text content (if available)
  • screenshot - Base64 screenshot (if available)
  • confidence - AI confidence score
  • width, height - Element dimensions
  • boundingBox - Complete bounding box
See Elements Reference for complete details.

JSON Serialization

You can serialize elements safely with JSON.stringify() for logs and for debug. TestDriver removes circular references automatically:
Use this for these:
  • To debug problems with element detection
  • To log the details of the test
  • To share element data between processes
  • To examine the cache performance

Best Practices

Be specific in descriptionsMore specific descriptions make the accuracy better:
Always check if foundMake sure that TestDriver found the elements before you interact with them:
Include visual or positional context

Confidence Threshold

Set a minimum confidence score for element matches. If the confidence is less than the threshold, find() makes the result “not found”:
Use this for these:
  • Critical test steps. An incorrect click can cause more failures.
  • To tell the difference between similar elements (for example, many buttons)
  • To fail quickly when the UI changed
The confidence value is a float between 0 and 1 (for example, 0.9 = 90%). The AI returns its confidence with each find result. You can also read this from element.confidence after a good find.

Element Type

Use the type option to show which kind of element you look for. This puts your description into a more specific prompt for the AI. It makes the match accuracy better, primarily when a description is short or not clear.
Use this primarily for short descriptions such as "Submit" or "Login". In these, the AI can be not sure to look for a button, a link, or visible text. When you give the type, the description becomes clear.

Polling for Dynamic Elements

By default, find() polls for a maximum of 10 seconds (it tries again each 5 seconds) until it finds the element. You can change this with the timeout option:
The timeout option:
  • Has a default of 10000 (10 seconds)
  • Tries to find the element again each 5 seconds
  • Stops when it finds the element or the timeout ends
  • Logs the progress during the poll
  • Returns the element (make a check with element.found() if it does not throw an error on a failure)
  • Set it to 0 to disable the poll and try one time

Zoom Mode

Zoom mode is disabled by default. It uses a two-phase method for more precision when it finds elements, primarily in full UIs that have many similar elements. To enable zoom for a specific find call, give zoom: true:

How Zoom Mode Works

  1. Phase 1: The AI finds the approximate location of the element.
  2. Phase 2: TestDriver makes a 30% crop of the screen around that location.
  3. Phase 3: The AI does the precise location on the cropped image.
  4. Result: TestDriver changes the coordinates back to the absolute screen position.
This two-phase method gives the AI a higher-resolution view of the target area. It makes the accuracy better when many similar elements are near together.
Enable zoom with zoom: true when:
  • You target small elements in full UIs that have many similar elements
  • You need more precision for UI elements that are near together

Verify Mode

Verify mode is disabled by default. When it is enabled, a second AI call makes sure that the coordinates from find() agree with the correct element. This catches incorrect positions.

How Verify Mode Works

  1. Phase 1: The AI finds the element and returns coordinates.
  2. Phase 2: A second AI call looks at the screenshot at those coordinates. It makes sure that the element agrees with the description.
  3. Result: If the verification fails, TestDriver tries the find again or marks it “not found”.

Combining Zoom and Verify

For the maximum accuracy, enable zoom and verify together. Use this for critical interactions. A click on the wrong element can cause more failures:

Cache Options

When a test completes correctly, TestDriver caches the result of each find(). On later runs, TestDriver uses the cached match again. It does not make a new AI call. This finds the same element much more quickly. The cache is in your dashboard. TestDriver shares it between runs. Read the Cache page to see how the match, the thresholds, and the invalidation work. Control the cache to make the performance better, primarily when you use dynamic variables in prompts.

Custom Cache Key

Use cacheKey to keep the cache clean when prompts have variables:

Cache Threshold

Control how similar a cached result must be before TestDriver uses it again:
By default, TestDriver makes a cache key automatically from the SHA-256 hash of your test file. When you change your test file, the hash changes automatically. This makes the old cache entries not valid.

Manual Polling (Alternative)

If you need custom poll logic:

Use Cases

Complete Example


findAll()

Locate all elements matching a description, rather than just one.

Syntax

Parameters

string
required
Natural language description of elements to find
object | number
Optional cache options (same as find())

Returns

Promise<Element[]> - Array of Element instances

Examples

Basic Usage

Finding Multiple Items

With Caching

Empty Results

Differences from find()

Use Cases

Complete Example

Best Practices

Handle empty arrays gracefully
Use find() for single elements
Cache for performance