fix(Playwright): skip visibleLocator for scrollTo and grab* methods - #5712
Open
DavertMik wants to merge 1 commit into
Open
fix(Playwright): skip visibleLocator for scrollTo and grab* methods#5712DavertMik wants to merge 1 commit into
DavertMik wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 andvisibility: hiddenelements, and those are exactly what people scroll to in order to reveal them:visibleLocator: falsevisibleLocator: true, before this PRopacity: 0until scrolled into viewvisibility: hiddenuntil scrolled into view<a id="x"></a>scrollTonow skips the filter, so thetruecolumn matches thefalsecolumn.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')grabValueFromon an<input type="hidden">grabHTMLFromon adisplay: noneelementgrabTextFromalready skipped the filter for CSS locators. Every step whose name starts withgrabnow 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
domPresenceStepstovisibilityAgnosticStepsand addedscrollTo._beforeStepalso exempts everygrab*step.visibleLocatorJSDoc anddocs/helpers/Playwright.md.visibility: hiddenelement and an empty anchor to/form/scroll.#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.🤖 Generated with Claude Code
https://claude.ai/code/session_01Gaie9qVda6jpWHogaHfnHZ