Skip to the page

UI automation · core

Playwright waits and web-first assertions

Playwright checks that an element is ready before each action and retries assertions. It still does not know when the app itself is ready.

The notes

What you must know

  • Before a click Playwright checks the element is visible, stable (same box for two animation frames), receives events (not covered), and enabled. It retries until the timeout.
  • Locators are lazy and found again for every action, so there is no stale element problem like in Selenium.
  • Web-first assertions such as await expect(locator).toHaveText("Paid") retry until true or timeout.
  • Reading textContent() once and asserting does not retry. It is a common cause of flaky tests.
  • Strict mode: acting on a locator that matches more than one element throws an error, so vague locators fail early.
  • Recommended locators: getByRole with a name, getByLabel, getByPlaceholder, getByText, getByTestId. CSS or XPath last.
  • Auto-waiting does not know about app readiness: data still loading, or a server-rendered page whose JavaScript has not attached yet.
  • Avoid force: true everywhere. It skips the checks that protect you.

The red pen

Common traps: mistake → fix

  • Mistake: Playwright never needs waits

    Fix: it does not know when your app finished loading data or attaching handlers.

  • Mistake: expect(await locator.textContent()).toBe(x) is fine

    Fix: it reads once and never retries.

  • Mistake: force: true fixes a failing click

    Fix: it hides a real problem such as an overlay.

Easy to hard

Questions interviewers ask, easy to hard

  1. What does Playwright check before it clicks?
  2. What is a web-first assertion?
  3. Why does Playwright not have a stale element problem?
  4. Give two ways to write a locator that Playwright recommends.

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview