fix(helpers): scroll element into view in moveCursorTo - #5715
Open
DavertMik wants to merge 1 commit into
Open
Conversation
moveCursorTo moved the mouse to the element's center coordinates without scrolling first. For an element outside the viewport the cursor landed off-screen and no hover fired, with no error. Playwright now calls scrollIntoViewIfNeeded() before reading the point. Puppeteer scrolls the element to the center when it is not fully in the viewport, the same check its own ElementHandle.hover() performs, using public API only. WebDriver needs no change: WebdriverIO's moveTo already scrolls into view. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VmYyNa6z4o3hxPkdpDiUmB
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.
Problem
moveCursorTomoved the mouse to the element's center coordinates without scrolling first. When the element was outside the viewport, the cursor landed off-screen and no hover fired. No error was raised, so the step passed while doing nothing.Fix
scrollIntoViewIfNeeded()on the located element before reading its clickable point.scrollToalready uses the same call.isIntersectingViewport({ threshold: 1 })), scroll it to the center. Puppeteer's ownElementHandle.hover()does the same. ItsscrollIntoViewIfNeeded()isprotected, and Puppeteer is not a peer dependency, so this sticks to public API.moveToalready scrolls into view.The offset arguments still work: the element is scrolled into view first, then the offset is added to its center.
Behavior change
Playwright only: if
moveCursorTotargets adisplay:noneelement (reachable whenvisibleLocatoris off), it used to fail immediately withElementNotFound. It now fails after the helpertimeout(5s by default) with Playwright's timeout error.Tests
margin-top: 2000px) totest/data/app/view/form/hover.php.#moveCursorToinPlaywright_test.jsandPuppeteer_test.js: one plain, one with a context. All four fail without the fix and pass with it.#moveCursorTo,#scrollToand#dragAndDropspecs pass for both helpers.🤖 Generated with Claude Code
https://claude.ai/code/session_01VmYyNa6z4o3hxPkdpDiUmB