Perform browser actions using natural language instructions with page.act()
The page.act() method allows you to control the browser using natural language instructions. The AI interprets your instruction, determines what actions to take, and executes them automatically.
await page.goto('https://example.com')// Click a buttonawait page.act('Click the sign up button')// Click a linkawait page.act('Click the privacy policy link')// Click by descriptionawait page.act('Click the blue submit button at the bottom')
// Fill a single fieldawait page.act('Fill in the email field with john@example.com')// Fill multiple fieldsawait page.act('Enter username "johndoe" and password "secret123"')// Select from dropdownawait page.act('Select "United States" from the country dropdown')// Check a checkboxawait page.act('Check the "I agree to terms" checkbox')
await page.goto('https://example.com/login')// AI performs multiple actions in sequenceawait page.act('Fill in the login form with username "john" and password "pass123", then click login')
await page.goto('https://example.com/products')// AI finds and interacts with dynamic elementsawait page.act('If there is a cookie consent banner, click accept')await page.act('Find the product with the lowest price and click on it')
// Scroll to find elementsawait page.act('Scroll down to the footer and click the contact link')// Navigate through pagesawait page.act('Click the next page button')
await page.goto('https://example.com/checkout')// Multi-step form completionconst result = await page.act(` Fill out the shipping form with: - Name: John Doe - Address: 123 Main St - City: San Francisco - ZIP: 94102 Then click continue`)if (result.success) { console.log('Form completed successfully') console.log('Actions taken:', result.actions)}
// Wait and interact with loaded contentawait page.act('Wait for the search results to load, then click the first result')// Handle popupsawait page.act('If a signup popup appears, close it')// Interact with carouselsawait page.act('Click the right arrow on the image carousel 3 times')
await page.goto('https://example.com/products')await page.act('Enter "laptop" in the search box and press enter')await page.act('Filter results by price: $500-$1000')await page.act('Sort by highest rating')
Be specific and descriptive. Instead of “click the button”, say “click the blue submit button at the bottom of the form”
Good:
await page.act('Click the red "Add to Cart" button next to the product image')await page.act('Fill in the email field in the login form with test@example.com')
Bad:
await page.act('Click it') // Too vagueawait page.act('Do the thing') // Not specific
For very complex workflows, break them into steps:
// Instead of one giant instructionawait page.act('Fill in the form')await page.act('Select shipping method')await page.act('Click continue to payment')
const result = await page.act('Click the checkout button')if (!result.success) { console.error('Action failed:', result.actions) // Try alternative approach or manual automation}
Mix AI actions with traditional automation for best results:
// Use AI for dynamic interactionsawait page.act('Accept cookie consent if it appears')// Use manual automation for precise controlawait page.click('#precise-selector')await page.input('#email', 'test@example.com')// Use AI for complex extractionawait page.act('Find and click the product with best rating')
await page.goto('https://example.com/login')await page.act('Click the "Sign in with Google" button')// Handle OAuth popup...await page.act('Click the authorize button')
await page.goto('https://shop.example.com')await page.act('Search for "wireless headphones"')await page.act('Filter by price under $100')await page.act('Click on the product with the highest rating')await page.act('Select black color and add to cart')
await page.goto('https://news.example.com')await page.act('Find and click the article about technology')await page.act('Scroll down and click "Load more comments"')