Skip to content

fix(helpers): scroll element into view in moveCursorTo - #5715

Open
DavertMik wants to merge 1 commit into
4.xfrom
fix/move-cursor-scroll-into-view
Open

fix(helpers): scroll element into view in moveCursorTo#5715
DavertMik wants to merge 1 commit into
4.xfrom
fix/move-cursor-scroll-into-view

Conversation

@DavertMik

Copy link
Copy Markdown
Contributor

Problem

moveCursorTo moved 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

  • Playwright: call scrollIntoViewIfNeeded() on the located element before reading its clickable point. scrollTo already uses the same call.
  • Puppeteer: if the element is not fully inside the viewport (isIntersectingViewport({ threshold: 1 })), scroll it to the center. Puppeteer's own ElementHandle.hover() does the same. Its scrollIntoViewIfNeeded() is protected, and Puppeteer is not a peer dependency, so this sticks to public API.
  • WebDriver: no change. WebdriverIO's moveTo already 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 moveCursorTo targets a display:none element (reachable when visibleLocator is off), it used to fail immediately with ElementNotFound. It now fails after the helper timeout (5s by default) with Playwright's timeout error.

Tests

  • Added an off-screen hover target (margin-top: 2000px) to test/data/app/view/form/hover.php.
  • Added two specs to #moveCursorTo in Playwright_test.js and Puppeteer_test.js: one plain, one with a context. All four fail without the fix and pass with it.
  • Existing #moveCursorTo, #scrollTo and #dragAndDrop specs pass for both helpers.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VmYyNa6z4o3hxPkdpDiUmB

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
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