[V3]: fix partially occluded clicks
Merged
SE
17d ago+855+855+012345678901234567890123456789-40-40-01234567890123456789
why
locator.click()clicks in the center of an element. if there is something covering the center of that element, then the click lands on the thing covering it
what changed
- added a shared
getClickPointhelper, which scrolls the element into view & decides which point to click - added a page side helper
findClickablePoint(called bygetClickPoint), which does hit testing. ie, it:- checks whether the element's center is actually reachable, or covered by something like a fixed footer or sticky header
- if covered, it scrolls the element to the center, end & start of the viewport & checks the center again at each position
- falls back to off-center points if the center is never reachable
- counts hits on a child of the element, inside its shadow root, or on its
<label>as reaching the element - scrolls instantly, so pages with smooth scrolling are measured after the scroll finishes
getClickPointmaps the chosen point onto the element's box model, so iframe offsets & transforms are handled as before- if every point is covered, it clicks the center like before & logs whatever is in the way
test plan
- added
locator-click-hit-target.spec.ts, which:- clicks & hovers a button partly under a fixed footer, & clicks a button partly under a sticky header. these fail without the fix
- checks that a fully covered element still gets a center click instead of throwing
- guards cases where the element on top is legitimately not the target: buttons in open & closed shadow roots, & two custom checkbox patterns where the native input is hidden under its label
- clicks buttons inside same-origin & cross-origin iframes, & on a page with smooth scrolling
- added
find-clickable-point.spec.ts, which runs the page-side script directly & checks:- no scrolling when nothing covers the element
- scrolling a button out from under a fixed footer, including with smooth scrolling
- falling back to an off-center point when scrolling can't help
- reporting what covers a fully covered element
- shadow roots & labels count as reaching the element
Summary by cubic
Fixes clicks landing on elements overlapping the target. click(), hover(), and tap() now hit-test the chosen point and scroll the element (under fixed footers, sticky headers, banners) to find a reachable one before dispatching input. centroid() intentionally stays at the box center even when covered.
- Adds
getClickPoint, shared by click, hover, and tap (not centroid), which scrolls into view and runs a newfindClickablePointin-page script. - The script tries the element's center at several scroll positions, then falls back to off-center points; it treats hits on descendants, shadow root content, and associated
<label>s as reaching the element. - If no point is reachable, it clicks the center as before and logs what is covering the element.
- Adds integration tests for fixed footers, sticky headers, shadow roots, hidden checkboxes, same- and cross-origin iframes, smooth scrolling, fully covered elements, and centroid staying at a covered center.