// 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"');
// 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();}