NashTech Blog

The Browser Rendering Pipeline Explained: Why Your Playwright Tests Fail

Table of Contents

Error: locator.click: Element is not attached to the DOM

TimeoutError: locator.click: Timeout 30000ms exceeded waiting for element to be visible

If you’ve written Playwright, Selenium, or Cypress tests for more than a few weeks, you’ve seen an error like these, usually on a test that “should just work,” running against a page that renders perfectly fine in your own browser. The instinct is to blame the automation framework: add a sleep, bump the timeout, retry the test. That instinct is almost always wrong.

Playwright is not guessing when it decides an element isn’t ready. It asks the browser’s rendering pipeline a specific, literal question: does this element have a box, is that box visible, has it stopped moving? The browser answers honestly. The test fails because the page hasn’t finished doing what pages do: parsing HTML, building a DOM, computing styles, laying out boxes, painting pixels, and compositing layers, all on a timeline your test script doesn’t control.

This guide explains that rendering pipeline in plain terms, then connects it directly to the automation failures you’ve probably already debugged. By the end, you’ll be able to look at a flaky test and reason about which part of the pipeline is actually responsible, instead of reaching for waitForTimeout().

1. Why Playwright Tests Fail

Automation tools don’t fail randomly. Every actionability error Playwright throws is a direct report on the state of the page at that instant: whether an element exists in the DOM, whether it has a visible box, and whether that box has stopped moving.

The confusion comes from a mismatch in mental models. Developers see a finished page and assume “the page is done.” The browser sees a sequence of stages, each of which can be re-run at any time by a script, a network response, or a CSS animation. Playwright sits between those two views, and it always trusts the browser, not what a screenshot appears to show.

Understanding the handful of rendering concepts below turns most “random” flakiness into a specific, fixable cause.

2. The Browser Rendering Model

Every page follows the same core pipeline before anything appears on screen:

  • DOM. The browser parses HTML into a tree of nodes. A plain <script> tag without async/defer pauses this step until it downloads and runs, which is why elements below a blocking script aren’t in the DOM yet while it executes.
  • CSSOM. The browser parses every stylesheet into a tree describing style rules. CSS is render-blocking by default: nothing paints until the full CSSOM is ready, because any later rule could still change an earlier element’s style.
  • Render tree. The DOM and CSSOM merge into a tree containing only what will actually be painted. This is the step that decides whether an element gets a box at all (more on this in Section 3).
  • Layout. The browser calculates the exact size and position of every box. This runs again any time geometry changes, and reading properties like offsetHeight right after a DOM write can force it to run synchronously mid-script.
  • Paint and compositing. Boxes become pixels, and the browser assembles independent layers (often driven by transform, opacity, or will-change) into the final frame, frequently on a separate compositor thread from the main thread.

JavaScript and frameworks like React, Vue, and Angular keep re-running parts of this pipeline dozens of times per second as they mutate the DOM in response to state changes, so a page you can see is rarely a page that has stopped changing.

3. Visible Doesn’t Mean Ready

This is the single most useful fact for debugging flaky tests: “visible” is not one simple state, and different kinds of invisibility behave completely differently.

  • display: none removes an element from the render tree entirely. It has no box, no size, no position, and it will never become visible no matter how long a test waits, because there’s nothing there to wait on.
  • visibility: hidden keeps the element’s box in the render tree and in layout. It occupies space and has real dimensions; it simply isn’t painted. Waiting here means waiting on a style change, not a structural one.
  • opacity: 0 keeps the element fully present and painted, just transparent. An element can be painted or otherwise present in the DOM but still fail Playwright’s visibility check if it has zero size or visibility: hidden. An element with opacity: 0 is still considered visible by Playwright, which is a common source of confusion when a test clicks something a user can’t actually see.

Two other gaps matter just as much:

  • Hydration. Server-rendered frameworks (Next.js, Nuxt, SvelteKit) send finished-looking HTML before attaching event listeners client-side. Between initial paint and hydration completing, an element can look ready and still do nothing when clicked, because no listener is attached yet.
  • Compositor animations. An animation driven purely by transform/opacity can keep running on the compositor thread even while the main thread is idle or busy with other JavaScript. This is why Playwright checks that an element’s bounding box is stable across two animation frames before treating it as ready to click.

4. Five Common Failure Patterns

4.1. Detached elements

A locator resolves to a real DOM node, then a framework re-render removes and replaces it. The reference your test held is now detached, even though a visually identical element exists in the new DOM.

Typical error: Element is not attached to the DOM

Fix: use a Playwright Locator, not a cached ElementHandle. Locators re-resolve the element on every action instead of holding a stale reference.

4.2. Overlay interception

A modal, toast, or sticky header sits visually on top of the target element, even though both exist in layout.

Typical error: element intercepts pointer events

Fix: dismiss the overlay explicitly instead of forcing the click. For overlays that appear unpredictably, register a handler once with page.addLocatorHandler() so it dismisses the overlay automatically before every action.

4.3. Hidden elements (display vs. visibility)

Playwright treats display: none and visibility: hidden as “not visible” for the same reason (no box, or unpainted box), but only one of them can ever change through a CSS toggle you’re waiting on.

Fix: wait on the actual state change with a web-first assertion instead of a fixed delay.

4.4. Hydration gaps

A click on a server-rendered element appears to succeed (no error thrown) but has no effect, because the JavaScript listener hasn’t attached yet.

Fix: wait for an app-specific “ready” signal, such as a data attribute the framework sets after hydration, instead of assuming DOM presence means interactivity.

4.5. Unstable animations

A continuous CSS animation (an infinite pulsing button, for example) never lets an element’s bounding box stay still across two frames, so Playwright’s stability check never passes.

Typical error: waiting for element to be stable

Fix: disable non-essential animations in the test environment.

5. How Playwright Auto-Waiting Helps

Playwright’s design targets the timing gap between a test script and the rendering pipeline directly, instead of papering over it with delays.

  • Locators, not handles. A Locator is re-evaluated fresh on every action, so it can’t go stale the way a cached ElementHandle can.
  • Actionability checks. Before every action, Playwright confirms the element is attached, visible, stable across animation frames, receiving pointer events, and enabled. That’s a direct, literal check against the rendering concepts in Sections 2 and 3.
  • Web-first assertions. Calls like expect(locator).toBeVisible() retry automatically until the condition holds or the timeout elapses, instead of checking once.
  • addLocatorHandler(). Declares once how to dismiss an overlay that might appear at any point, and Playwright checks for it before every action.
  • Trace Viewer. Records DOM snapshots, screenshots, network activity, and console output around each action, so “why did this fail” becomes an inspection instead of a guess.

6. Practical Debugging Checklist

Instead ofDo this
CSS/class selectors (.btn.btn-primary)Role or test-id locators (getByRole, getByTestId)
page.waitForTimeout(3000)await expect(locator).toBeVisible()
{ force: true } on a flaky clickFind out which actionability check is actually failing first
Leaving all animations enabled in CIDisabling animation/transition durations for test runs
Re-running a flaky test until it passesRecording a trace on first retry and reading the DOM snapshots

7. Conclusion

A browser rendering a page and Playwright driving a test are running the same race on the same track, and most “flaky test” bugs are the automation script losing track of where the browser actually is. HTML parsing determines when nodes exist. The render tree determines when they have a box. Layout determines where that box is. Paint and compositing determine what’s actually on screen versus merely present. JavaScript and frameworks keep restarting all of it.

Once you can name the specific pipeline stage behind a failure, whether that’s a detached node, an excluded render-tree box, an unstable animation, or an un-hydrated listener, the fix stops being a guess and becomes a targeted change: the right locator, the right assertion, or the right wait.

Playwright’s actionability model isn’t an obstacle to work around. It’s a faithful map of the same pipeline this article just walked through.

Picture of Truong Bui Quang

Truong Bui Quang

Leave a Comment

Suggested Article

Scroll to Top