Custom cache key for storing element location. Use this to prevent cache pollution when using dynamic variables in prompts, or to share cache across tests.
Minimum confidence threshold (0-1). If the AI’s confidence score for the found element is below this value, the find will be treated as a failure (element.found() returns false). Useful for ensuring high-quality matches in critical test steps.
// Provide location contextconst field = await testdriver.find('username input in the login form');const button = await testdriver.find('delete button in the top right corner');// Describe nearby elementsconst input = await testdriver.find('input field below the email label');const checkbox = await testdriver.find('checkbox next to "Remember me"');// Describe visual positionconst menu = await testdriver.find('hamburger menu icon in the top left');
Be specific in descriptionsMore specific descriptions improve accuracy:
Copy
// ✅ Goodawait testdriver.find('blue submit button below the email field');// ❌ Too vagueawait testdriver.find('button');
Always check if foundVerify elements were located before interacting:
Copy
const element = await testdriver.find('login button');if (!element.found()) { throw new Error('Login button not found');}await element.click();
Include visual or positional context
Copy
// Include colorawait testdriver.find('red error icon');// Include positionawait testdriver.find('search button in the top navigation bar');// Include nearby textawait testdriver.find('checkbox next to "I agree to terms"');
Require a minimum AI confidence score for element matches. If the confidence is below the threshold, find() treats the result as not found:
Copy
// Require at least 90% confidenceconst element = await testdriver.find('submit button', { confidence: 0.9 });if (!element.found()) { // AI found something but wasn't confident enough throw new Error('Could not confidently locate submit button');}await element.click();
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
Copy
// Combine with timeout for robust polling with confidence gateconst element = await testdriver.find('success notification', { confidence: 0.85, timeout: 15000,});
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.
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.
Copy
// Find text on the pageconst label = await testdriver.find('Sign In', { type: 'text' });// AI prompt becomes: The text "Sign In"// Find an imageconst logo = await testdriver.find('company logo', { type: 'image' });// AI prompt becomes: The image "company logo"// Find a UI element (button, input, checkbox, etc.)const btn = await testdriver.find('Submit', { type: 'ui' });// AI prompt becomes: The UI element "Submit"// No wrapping — same as omitting the optionconst el = await testdriver.find('the blue submit button', { type: 'any' });
Type
Prompt sent to AI
"text"
The text "..."
"image"
The image "..."
"ui"
The UI element "..."
"any"
Original description (no wrapping)
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.
For elements that may not be immediately visible, use the timeout option to automatically poll:
Copy
// Poll for element (retries every 5 seconds until found or timeout)const element = await testdriver.find('login button', { timeout: 30000 });await element.click();
The timeout option:
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)
Phase 1: AI identifies the approximate location of the element
Phase 2: A 30% crop of the screen is created around that location
Phase 3: AI performs precise location on the zoomed/cropped image
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.
Use zoom: true when:
Clicking small icons in toolbars
Selecting from a grid of similar items
Targeting elements in dense UI areas
The default locate is clicking the wrong similar element
You get an AI verification rejection like “The crosshair is located in the empty space of the browser’s tab bar/title bar area” — this means the initial locate was imprecise and zoom will help the AI pinpoint the correct element
Copy
// Without zoom - may click wrong icon in toolbarconst icon = await testdriver.find('settings icon');// With zoom - better precision for crowded areasconst icon = await testdriver.find('settings icon', { zoom: true });
Use cacheKey to prevent cache pollution when prompts contain variables:
Copy
// ❌ Without cacheKey - creates new cache entry for each email valueconst email = 'user@example.com';await testdriver.find(`input for ${email}`); // Cache miss every time// ✅ With cacheKey - reuses cache regardless of variableconst email = 'user@example.com';await testdriver.find(`input for ${email}`, { cacheKey: 'email-input'});// Also useful for dynamic IDs, names, or other changing dataconst orderId = generateOrderId();await testdriver.find(`order ${orderId} status`, { cacheKey: 'order-status' // Same cache for all orders});
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.
// Wait for loading to completelet content;for (let i = 0; i < 30; i++) { content = await testdriver.find('results table'); if (content.found()) break; await new Promise(r => setTimeout(r, 1000));}// Interact with loaded contentconst firstRow = await testdriver.find('first row in the results table');await firstRow.click();
Complex UI Elements
Copy
// Modals and dialogsconst modal = await testdriver.find('confirmation dialog');if (modal.found()) { const confirmBtn = await testdriver.find('confirm button in the dialog'); await confirmBtn.click();}// Dropdown menusconst dropdown = await testdriver.find('country dropdown');await dropdown.click();const option = await testdriver.find('United States option');await option.click();
// Find all rows in a tableconst rows = await testdriver.findAll('table row');// Click every rowfor (const row of rows) { await row.click(); await new Promise(r => setTimeout(r, 500)); // Wait between clicks}// Or click specific rowawait rows[2].click(); // Click third row
Checkboxes/Radio Buttons
Copy
// Find all checkboxesconst checkboxes = await testdriver.findAll('checkbox');// Check all boxesfor (const checkbox of checkboxes) { await checkbox.click();}// Or select first uncheckedconst unchecked = checkboxes[0];await unchecked.click();
Navigation Links
Copy
// Find all navigation linksconst navLinks = await testdriver.findAll('navigation link');// Validate all are presentexpect(navLinks.length).toBeGreaterThan(0);// Click specific link by textconst homeLink = navLinks.find(link => link.text?.toLowerCase().includes('home'));if (homeLink) { await homeLink.click();}