Skip to content

fix(Playwright): skip visibleLocator for scrollTo and grab* methods - #5712

Open
DavertMik wants to merge 1 commit into
4.xfrom
fix/visible-locator-scroll-grab
Open

fix(Playwright): skip visibleLocator for scrollTo and grab* methods#5712
DavertMik wants to merge 1 commit into
4.xfrom
fix/visible-locator-scroll-grab

Conversation

@DavertMik

Copy link
Copy Markdown
Contributor

Follow-up to #5707. With visibleLocator: true, some steps that must reach hidden elements failed with "element not found".

scrollTo

Playwright's visible() treats off-screen elements as visible, so ordinary below-the-fold scrolling kept working. It drops zero-size and visibility: hidden elements, and those are exactly what people scroll to in order to reveal them:

Target visibleLocator: false visibleLocator: true, before this PR
Element below the fold works works
Element inside a scrollable container works works
opacity: 0 until scrolled into view works works
visibility: hidden until scrolled into view works not found
Empty anchor <a id="x"></a> works not found
Zero-height infinite-scroll sentinel works not found

scrollTo now skips the filter, so the true column matches the false column.

grab* methods

These read hidden elements on purpose. With visibleLocator: true, all of these failed with "element not found":

  • grabAttributeFrom('meta[name="csrf-token"]', 'content')
  • grabValueFrom on an <input type="hidden">
  • grabHTMLFrom on a display: none element

grabTextFrom already skipped the filter for CSS locators. Every step whose name starts with grab now skips it.

Trade-off

If a hidden duplicate comes before the visible element in the DOM, these steps pick the hidden one, as in 3.x and with visibleLocator: false. stepOpts({ visibleLocator: true }) turns the filter back on for a single step.

Changes

  • Renamed domPresenceSteps to visibilityAgnosticSteps and added scrollTo. _beforeStep also exempts every grab* step.
  • Updated the visibleLocator JSDoc and docs/helpers/Playwright.md.
  • Added a visibility: hidden element and an empty anchor to /form/scroll.
  • Added two tests to #visibleLocator. Both fail with "element not found" without the fix.

Test plan

  • mocha test/helper/Playwright_test.js --grep "visibleLocator|scroll: |grab": 101 pass. One unrelated failure, should see recording traffics: it waits for an image the live codecept.io site no longer serves, and the test comment already says so.
  • CI

🤖 Generated with Claude Code

https://claude.ai/code/session_01Gaie9qVda6jpWHogaHfnHZ

scrollTo must reach elements that scrolling reveals: scroll-reveal
elements hidden with visibility:hidden, empty anchors and zero-height
infinite-scroll sentinels. Playwright's visible() drops them, so
scrollTo failed with "element not found". Off-screen and opacity:0
elements were never affected.

grab* methods read hidden elements on purpose: csrf-token meta tags,
hidden inputs, collapsed content. They skip the filter too, which also
makes grabTextFrom consistent with the rest of the family.

stepOpts({ visibleLocator: true }) still re-enables the filter for a
single step.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gaie9qVda6jpWHogaHfnHZ
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.

1 participant