#The actionability checks
AddedBefore an action, Playwright doesn't just find the element; it waits until a real user could do that action to it. A person can't click a button that's greyed out, hidden, sliding across the screen or covered by a cookie banner, so Playwright doesn't either. These are the actionability checks, and they're the "auto" in auto-waiting (Chapter 1).
The checks, as the docs define them:
- Visible: a non-empty bounding box and not
visibility: hidden. (opacity: 0still counts as visible.) - Stable: the same bounding box for at least two animation frames in a row, so it isn't mid-animation.
- Enabled: not
disabled, not inside a disabled<fieldset>, not inside anaria-disabled="true"element. - Editable: enabled and not
readonly. - Receives events: the element is what's actually under the pointer at the click point, not an overlay.
- Not inert (1.65+): not inside an element with the
inertattribute.
Not every action needs every check. From the docs' table:
| Action | Visible | Stable | Receives events | Enabled | Editable | Not inert |
|---|---|---|---|---|---|---|
click, dblclick, check, uncheck, setChecked, tap | ✓ | ✓ | ✓ | ✓ | ✓ | |
hover, dragTo | ✓ | ✓ | ✓ | |||
fill, clear | ✓ | ✓ | ✓ | ✓ | ||
selectOption | ✓ | ✓ | ✓ | |||
screenshot | ✓ | ✓ | ||||
focus, press, pressSequentially, setInputFiles, blur, dispatchEvent |
The last row matters: press, pressSequentially and setInputFiles wait for the element to exist but check nothing else, because a key press goes to whatever has focus and a file input is usually invisible on purpose.
The mental model: a patient user with a checklist. Before each click they ask "can I see it, has it stopped moving, is it greyed out, is something on top of it?" and wait until every answer is right. If the timeout runs out first, the error's call log says which question kept failing.
import { test, expect, type Page } from "@playwright/test";
async function signIn(page: Page, path = "/practice/shop") {
await page.goto(path);
await page.getByLabel("Username").fill("rohit");
await page.getByLabel("Password").fill("playwright");
await page.getByRole("button", { name: "Sign in" }).click();
await expect(page).toHaveURL(path);
}
const addButton = (page: Page, product: string) =>
page.getByRole("listitem").filter({ hasText: product }).getByRole("button", { name: "Add to cart" });
// The call log is part of the error message (with terminal colour codes). Keep its distinct lines that say what was wrong.
const why = (e: Error) =>
[...new Set(e.message.replace(/\u001b\[\d+m/g, "").split("\n").map((l) => l.trim()).filter((l) => /^- (element is|<.+> intercepts)/.test(l)))];
test("a disabled button is never clicked", async ({ page }) => {
await signIn(page);
const error = await addButton(page, "Vertical Mouse").click({ timeout: 2000 }).catch((e: Error) => e);
console.log("sold out:", why(error));
await expect(page.getByRole("link", { name: "Cart (0)" })).toBeVisible();
});
test("a covered button is never clicked", async ({ page }) => {
await signIn(page);
await expect(addButton(page, "Wireless Mouse")).toBeEnabled();
// A full-screen cookie banner, the kind that ships by accident.
await page.evaluate(() => document.body.insertAdjacentHTML("beforeend", '<div class="cookie-banner" style="position:fixed;inset:0;background:#0008">We use cookies</div>'));
const error = await addButton(page, "Wireless Mouse").click({ timeout: 2000 }).catch((e: Error) => e);
console.log("covered:", why(error));
});
test("an inert part of the page can't be clicked or filled (1.65+)", async ({ page }) => {
await signIn(page);
await expect(addButton(page, "Wireless Mouse")).toBeEnabled();
await page.evaluate(() => (document.querySelector("main")!.inert = true)); // what a modal does to the page behind it
const click = await addButton(page, "Wireless Mouse").click({ timeout: 2000 }).catch((e: Error) => e);
const fill = await page.getByLabel("Search products").fill("mouse", { timeout: 2000 }).catch((e: Error) => e);
console.log("inert click:", why(click), "inert fill:", why(fill));
});
test("trial: true runs the checks without acting", async ({ page }) => {
await signIn(page);
await addButton(page, "Wireless Mouse").click({ trial: true });
await expect(page.getByRole("link", { name: "Cart (0)" })).toBeVisible();
});Running 4 tests using 1 worker
sold out: [ '- element is not enabled' ]
✓ 1 [chromium] › tests/actionability.spec.ts:16:1 › a disabled button is never clicked (3.1s)
covered: [
'- element is visible, enabled and stable',
'- <div class="cookie-banner">We use cookies</div> intercepts pointer events'
]
✓ 2 [chromium] › tests/actionability.spec.ts:23:1 › a covered button is never clicked (3.8s)
inert click: [ '- element is inert' ] inert fill: [ '- element is inert' ]
✓ 3 [chromium] › tests/actionability.spec.ts:32:1 › an inert part of the page can't be clicked or filled (1.65+) (5.9s)
✓ 4 [chromium] › tests/actionability.spec.ts:41:1 › trial: true runs the checks without acting (1.9s)
4 passed (15.3s)whyis a small helper for this page: when an action times out, Playwright's error message includes a call log of every attempt (each line wrapped in terminal colour codes, whichwhystrips), andwhykeeps only its distinct lines that start "element is…" or "… intercepts". In a real failing test you'd read the whole call log in the report.- Disabled. The sold-out Vertical Mouse's button has the
disabledattribute.click()finds it at once, then keeps re-checking for 2 seconds and gives up; the reason is "element is not enabled". The cart stays at 0: no click was ever sent. - Covered. The test first waits for the products, then adds a fixed, full-screen banner. The button is visible, enabled and stable (the first line), but the point Playwright would click belongs to the banner, so it reports
<div class="cookie-banner">We use cookies</div> intercepts pointer eventsand retries, scrolling and checking again, until the timeout. A real user couldn't click it either, and that's the point: the test fails exactly when the user would be stuck. - Inert. Setting
inerton<main>is what a modal dialog does to the page behind it. Since 1.65,clickandfillboth wait for "not inert" (the release notes list it as a behaviour change), and both report "element is inert". A user can't reach anything behind an open modal, and now neither can the test. - Trial.
click({ trial: true })waits for every check to pass and then doesn't click. The cart stays at 0. It's handy for "wait until this is clickable" without side effects, for example before taking a screenshot.
Actions have no timeout of their own by default: actionTimeout is 0, so an action waits until the test times out (30 seconds by default). That's why a stuck click often shows up as "Test timeout of 30000ms exceeded" rather than an action timeout. Set use: { actionTimeout: 10_000 } in the config to get a clearer error sooner, or pass { timeout } to one action, as the tests above do. Navigations have navigationTimeout the same way. Assertions are different: they default to 5 seconds (Chapter 6).