Skip to main content

Overview

The TestDriver element finding system uses AI. It finds elements on the screen with natural language descriptions. The find() method returns an Element object. You can interact with the object.

Finding Elements

find()

Find an element on the screen with a natural language description.
Parameters:
  • description (string) - A natural language description of the element to find
Returns: Promise<Element> - The Element instance that TestDriver found Example:
Be specific in your descriptions. Include visual details, location context, or nearby text to make the accuracy better.

Element Class

The Element class represents a located (or to-be-located) UI element. It provides methods for interaction and properties for element information. For interaction methods like click() and hover(), see Interacting With Your App.

Methods

found()

Check if the element was successfully located.
Returns: boolean - True if element coordinates were found Example:

find()

Re-locate the element, optionally with a new description.
Parameters:
  • newDescription (string, optional) - New description to search for
Returns: Promise<Element> - This element instance Example:

Properties

Element properties provide additional information about located elements. Properties are available after a successful find() call.

coordinates

Get the element’s coordinates object containing all position information.
Returns: Object | null - Coordinate object with { x, y, centerX, centerY } Example:

x, y, centerX, centerY

Direct access to coordinate values. Always available after successful find().
Example:

width, height

Element dimensions in pixels. Available when AI detects element bounds.
Example:

boundingBox

Complete bounding box information including position and dimensions.
Returns: Object | null - Bounding box with all dimension data
Example:

screenshot

Base64-encoded PNG screenshot of the screen when element was found. Only available in DEBUG mode or when an error occurs.
Returns: string | null - Base64-encoded PNG image Example:
Screenshots can be large. They’re automatically excluded from error messages to prevent memory issues.

text

Text content extracted from the element by AI (if available).
Returns: string | null - Element’s text content Example:

label

Accessible label or name of the element (if available). Useful for verifying accessibility.
Returns: string | null - Accessible label Example:

confidence

AI confidence score for the element match (0-1, where 1 is perfect confidence).
Returns: number | null - Confidence score between 0 and 1 Example:
Confidence scores below 0.8 may indicate the element description was ambiguous or the wrong element was found.

Property Availability

Properties marked with ⚠️ may be null depending on what the AI could detect from the screenshot.

JSON Serialization

Element objects can be safely serialized using JSON.stringify() for logging, debugging, and data storage. Circular references are automatically removed:
Serialized output includes:
Serialized properties: Use cases:
Use JSON serialization when you need to log element data or when debugging why an element wasn’t found. The serialized output excludes large binary data (screenshots) and circular references.

Best Practices

Include visual details, position context, and nearby text:
Always verify elements were located before interacting: