Skip to content

test_driver.click() is unreliable because of coordinate rounding issues #53239

Open
@smfr

Description

@smfr
Contributor

test_driver.click() has issues when targeting an element of which only a sliver is visible at the bottom of the viewport. This happens in css/selectors/focus-visible-018-2.html.

test_driver.click() is basically this:

let box = element.getClientRects[0];
let middle = centerOfBoxClippingToViewport(box);
let elements = document.elementsFromPoint(middle.x, middle.y)
if (!elements)
   element.scrollIntoView();

box = element.getClientRects[0];
middle = centerOfBoxClippingToViewport(box);

dispatch_simulated_click(middle.x, middle.y);

Now consider this scenario: the target element has a clientRect.top of 599.5px. element.getClientRects() returns a value with fractional pixels, returns a rect that is 0.5px tall in a 600px tall viewport, and we compute the center with y=599.75. document.elementsFromPoint() at that location succeeds in finding the element, because it takes fractional coordinates.

Now we dispatch a simulated click, which floors the x and y coords, since mouseEvent.x and y are long, so we dispatch an event with y=599, and fail to hit the element.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @smfr

      Issue actions

        test_driver.click() is unreliable because of coordinate rounding issues · Issue #53239 · web-platform-tests/wpt