80 / 168 · 01 Agent Skills for Browser Automation · Test Patterns for AI-Driven Browser Automation← prev⊞ allnext →☰ Read as one page
11.6Pattern 5: Async Operations (Uploads, Debounce)
For operations that don't complete immediately (AJAX calls, file uploads, etc.). Actions auto-wait for their target element, which covers most cases; for long-running operations, poll observable state via eval or re-snapshot.
Example: File Upload
playwright-cli goto https://app.example.com/upload
playwright-cli snapshot
# → button "Choose file" [ref=e6]
playwright-cli upload e6 ./fixtures/report.pdf
# Poll for completion instead of a blind sleep
playwright-cli eval "document.querySelector('.upload-status')?.textContent"
# → "Uploading… 47%" → agent re-checks until:
# → "Upload complete"
Example: Search with Debounce
playwright-cli goto https://app.example.com/search
playwright-cli snapshot
# → searchbox "Search" [ref=e3]
playwright-cli fill e3 "test query"
playwright-cli snapshot
# → Agent verifies results region: "15 results found"
# (if results haven't rendered yet, the agent re-snapshots — judgment, not sleep())