</>

Technology

Playwright

Difficulty

Beginner

Interview Question

What is auto-waiting in Playwright?

Answer

What is Auto-Waiting in Playwright?

Auto-waiting is one of Playwright's most powerful features. Before every action (click, fill, check, etc.), Playwright automatically waits for the target element to be in an actionable state — without you writing any wait code.

What Playwright Checks Before Each Action

When you call locator.click(), Playwright waits for ALL of these:

CheckDescription
AttachedElement exists in the DOM
VisibleElement is visible (not display:none, not opacity:0, not zero size)
StableElement is not animating or moving
EnabledElement is not disabled
EditableFor fill/type — element is not readonly
Receives EventsNo overlay is blocking the element

Before Auto-waiting (Selenium-style)

Java
// Selenium — you had to write this manually
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));
driver.findElement(By.id("submit")).click();

With Playwright Auto-waiting

TypeScript
// Playwright — just click. It waits automatically.
await page.getByRole('button', { name: 'Submit' }).click();

Auto-waiting in Assertions

expect() also retries automatically — it re-checks until the assertion passes or times out:

TypeScript
// Playwright retries this assertion until it's true (up to timeout)
await expect(page.locator('.success-banner')).toBeVisible();
await expect(page.locator('#count')).toHaveText('10');

No need for sleep(2000) before checking!

Default Timeouts

ContextDefault Timeout
Action timeout (click, fill, etc.)30 seconds
expect() assertion5 seconds
page.goto() navigation30 seconds

Override globally in config:

TypeScript
// playwright.config.ts
export default defineConfig({
  use: {
    actionTimeout: 10_000,    // 10s per action
    navigationTimeout: 30_000, // 30s for navigation
  },
  expect: { timeout: 10_000 }, // 10s for assertions
});

Override per action:

TypeScript
await page.locator('#slow-element').click({ timeout: 60000 });

Why This Eliminates Flakiness

Most test flakiness comes from timing issues — an element isn't ready yet when the test tries to interact with it. Auto-waiting directly solves this by making every interaction inherently wait for the right state.

Follow AutomateQA

Related Topics