Skip to main content

Overview

Locate UI elements on screen using AI-powered natural language descriptions. Returns an Element object that can be interacted with.

Syntax

Parameters

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

Returns

Promise<Element> - Element instance that has been automatically located

Examples

Basic Element Finding

Finding with Context

Interacting with Found Elements

Element Object

The returned Element object provides:

Methods

  • found() - Check if element was located
  • click(action) - Click the element
  • hover() - Hover over the element
  • doubleClick() - Double-click the element
  • rightClick() - Right-click the element
  • find(newDescription) - Re-locate with 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

Elements can be safely serialized using JSON.stringify() for logging and debugging. Circular references are automatically removed:
This is useful for:
  • Debugging element detection issues
  • Logging test execution details
  • Sharing element information across processes
  • Analyzing cache performance

Best Practices

Be specific in descriptionsMore specific descriptions improve accuracy:
Always check if foundVerify elements were located before interacting:
Include visual or positional context

Confidence Threshold

Require a minimum AI confidence score for element matches. If the confidence is below the threshold, find() treats the result as not found:
This is useful for:
  • Critical test steps where an incorrect click could cause cascading failures
  • Distinguishing between similar elements (e.g., multiple buttons)
  • Failing fast when the UI has changed unexpectedly
The confidence value is a float between 0 and 1 (e.g., 0.9 = 90%). The AI returns its confidence with each find result, which you can also read from element.confidence after a successful find.

Element Type

Use the type option to hint what kind of element you’re looking for. This wraps your description into a more specific prompt for the AI, improving match accuracy — especially when users provide short or ambiguous descriptions.
This is particularly useful for short descriptions like "Submit" or "Login" where the AI may not know whether to look for a button, a link, or visible text. Specifying type removes the ambiguity.

Polling for Dynamic Elements

By default, find() polls for up to 10 seconds (retrying every 5 seconds) until the element is found. You can customize this with the timeout option:
The timeout option:
  • Defaults to 10000 (10 seconds)
  • Retries finding the element every 5 seconds
  • Stops when the element is found or the timeout expires
  • Logs progress during polling
  • Returns the element (check element.found() if not throwing on failure)
  • Set to 0 to disable polling and make a single attempt

Zoom Mode

Zoom mode is disabled by default. It uses a two-phase approach for better precision when locating elements, especially in crowded UIs with many similar elements. To enable zoom for a specific find call, pass zoom: true:

How Zoom Mode Works

  1. Phase 1: AI identifies the approximate location of the element
  2. Phase 2: A 30% crop of the screen is created around that location
  3. Phase 3: AI performs precise location on the zoomed/cropped image
  4. Result: Coordinates are converted back to absolute screen position
This two-phase approach gives the AI a higher-resolution view of the target area, improving accuracy when multiple similar elements are close together.
You may want to enable zoom with zoom: true when:
  • Targeting small elements in crowded UIs with many similar elements
  • You need extra precision for closely spaced UI elements

Verify Mode

Verify mode is disabled by default. When enabled, a second AI call checks that the coordinates returned by find() actually correspond to the requested element, catching hallucinated or incorrect positions.

How Verify Mode Works

  1. Phase 1: AI locates the element and returns coordinates
  2. Phase 2: A second AI call examines the screenshot at those coordinates to confirm the element matches the description
  3. Result: If verification fails, the find is retried or marked as not found

Combining Zoom and Verify

For maximum accuracy, enable both zoom and verify together. This is useful for critical interactions where clicking the wrong element could cause cascading failures:

Cache Options

When a test completes successfully, the result of each find() is cached. On later runs, TestDriver reuses the cached match instead of making a fresh AI call, which significantly speeds up locating the same element. The cache lives in your dashboard and is shared across runs — see the Cache page for how matching, thresholds, and invalidation work. Control caching behavior to optimize performance, especially when using dynamic variables in prompts.

Custom Cache Key

Use cacheKey to prevent cache pollution when prompts contain variables:

Cache Threshold

Control how similar a cached result must be to reuse it:
By default, TestDriver auto-generates a cache key from the SHA-256 hash of your test file. When you modify your test file, the hash changes automatically, invalidating stale cache entries.

Manual Polling (Alternative)

If you need custom polling 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