Chapter 43: Auto-waiting and timeouts
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Auto-waiting and timeouts
Playwright checks actionability before many actions, including visibility, stability, event reception and enabled state where relevant. Different operations have different checks. Test, action and assertion timeouts are distinct. Use observable readiness rather than sleep.
How it works
Step-by-step walkthrough
- Create a disabled button
- Enable it after a delay
- Let the locator wait
Example
import { test, expect } from '@playwright/test';
test('chapter 43 practice', async ({ page }) => {
await page.setContent('<button disabled>Save</button><script>setTimeout(() => document.querySelector("button").disabled = false, 500)</script>');
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByRole('button')).toBeEnabled();
});Avoid page.waitForTimeout in production tests.
Practice application screenshot
✎ Your practice task
Increase the delay and observe the behavior.
Knowledge check
What should replace a fixed sleep for a visible element?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.