Skip to content

fix(locator): treat elements inside visibility: hidden frames as hidden - #42722

Open
Mohan Ram (mohanram-dev) wants to merge 1 commit into
microsoft:mainfrom
mohanram-dev:fix/frame-visibility-hidden
Open

Mohan Ram (mohanram-dev) wants to merge 1 commit into
microsoft:mainfrom
mohanram-dev:fix/frame-visibility-hidden

Conversation

@mohanram-dev

@mohanram-dev Mohan Ram (mohanram-dev) commented Sep 15, 2026

Copy link
Copy Markdown

Fixes #42719

Description

When an <iframe> or one of its ancestor containers in the parent document has \�isibility: hidden, elements rendered inside the iframe were previously reported as visible (\isVisible() === true, \ oBeVisible()\ passing, and actionability checks attempting clicks and hitting pointer interception timeouts).

Root Cause

In \computeElementStyleVisibilityVisible()\ (\packages/injected/src/domUtils.ts), visibility was calculated solely within \element.ownerDocument. Because CSS inheritance of \�isibility: hidden\ does not traverse document boundaries, the inner iframe document creates a new root element which defaults to \�isibility: visible. Since \�isibility: hidden\ does not collapse layout boxes like \display: none\ does, \getBoundingClientRect()\ inside the iframe still reported non-zero dimensions.

Fix

In \computeElementStyleVisibilityVisible(), check if the element belongs to an enclosing frame via \element.ownerDocument?.defaultView?.frameElement. If present, check \isElementStyleVisibilityVisible(frameElement). This properly respects:

  1. Direct \�isibility: hidden\ on the <iframe> element.
  2. \�isibility: hidden\ inherited from ancestor containers in parent documents.
  3. Nested iframes.
  4. CSS override behavior where a frame with \�isibility: visible\ inside a \�isibility: hidden\ container remains visible.
  5. Caching and graceful handling across frame boundaries.

Tests Added

Added test cases in \ ests/page/locator-is-visible.spec.ts\ validating:

  • Direct \�isibility: hidden\ iframe.
  • Container \�isibility: hidden\ holding iframe.
  • Container \�isibility: hidden\ with \�isibility: visible\ iframe override.
  • Nested iframes with outer iframe hidden.
  • Dynamic visibility toggling on the iframe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: frame with visibility: hidden is incorrectly treated as visible

1 participant