What is Auto-waiting?
Playwright automatically waits for elements to be ready before performing actions. This eliminates the need for manual waits and makes tests more reliable.Unlike many testing frameworks that require explicit waits, Playwright waits automatically for actionability checks.
Actionability Checks
Before performing an action, Playwright waits for the element to pass several checks:1
Attached
Element is attached to the DOM
2
Visible
Element is visible (not
display: none, visibility: hidden, empty width/height, etc.)3
Stable
Element is not animating or moving
4
Enabled
Element is not disabled (for input elements)
5
Editable
Element is not readonly (for input actions like fill)
6
Receives Events
Element is not covered by other elements
Automatic Waiting in Action
Actions with Auto-waiting
All these actions wait automatically:Click Actions
Input Actions
Selection Actions
Locator Auto-waiting
Locators wait automatically when performing actions:Wait States
Playwright supports different wait states:attached
visible
hidden
detached
Navigation Auto-waiting
Navigation methods wait for the page to load:Load States
load-loadevent fired (default)domcontentloaded-DOMContentLoadedevent firednetworkidle- No network connections for 500mscommit- Navigation committed, DOM is interactive
Explicit Waits
When auto-waiting isn’t enough, use explicit waits:waitForSelector
waitForLoadState
waitForURL
waitForFunction
waitForEvent
waitForRequest
waitForResponse
waitForTimeout
Retries and Stability
Playwright retries checks until they pass or timeout:Stability Checks
Playwright ensures elements are stable before interacting:- Take two element positions
- Wait 100ms
- Compare positions
- Retry if positions changed
Visibility Checks
Elements must be visible to interact:- Not
display: none - Not
visibility: hidden - Not
opacity: 0 - Has size (
width > 0andheight > 0) - Not behind other elements
Editable Checks
Input elements must be editable:- Not
readonly - Not
disabled - Is an input element
Enabled Checks
- Not
disabledattribute - Not inside disabled fieldset
- Not disabled via ARIA
Timeout Configuration
Default Timeouts
Per-action Timeouts
Best Practices
Trust Auto-waiting
Trust Auto-waiting
Don’t add unnecessary explicit waits.
Use Appropriate Wait States
Use Appropriate Wait States
Choose the right wait state for navigation.
Wait for Specific Conditions
Wait for Specific Conditions
Use waitForFunction for complex conditions.
Handle Dynamic Content
Handle Dynamic Content
Wait for content to stabilize.
Debugging Waits
Common Patterns
Wait for Multiple Elements
Wait for API Response
Wait for Navigation
Wait for Element Count
Error Messages
When waits timeout, Playwright provides helpful errors:Next Steps
Test Isolation
Ensuring test independence
Assertions
Testing expectations
Debugging
Debugging failed tests
