Bug 232996

Summary: rect returns wrong coordinates after calling scrollIntoView
Product: WebKit Reporter: sebastian.klaar
Component: WebDriverAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Major CC: bburg, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: Mac (Intel)   
OS: macOS 11   

Description sebastian.klaar 2021-11-11 06:38:21 PST
We're using webdriverio to execute automated tests on Safari.

The w3c command "scrollIntoView" causes the following command to return wrong coordinates:
/session/:sessionId/element/:elementId/rect": {
"GET": {
"command": "getElementRect",
"description": "The Get Element Rect command returns the dimensions and coordinates of the given web element.",
"ref": "https://w3c.github.io/webdriver/#dfn-get-element-rect",
"variables": [{
"name": "elementId",
"description": "the id of an element returned in a previous call to Find Element(s)"
}],
"parameters": [],
"returns": {
"type": "Object",
"name": "elementRect",
"description": "A JSON object representing the position and bounding rect of the element."
}
}
}, 

The returned values are off by the amount of scroll range. According to the w3c specification "rect" should return coordinates relative to the browsing context and not to the viewport.
Comment 1 sebastian.klaar 2021-11-11 06:38:43 PST
reference: https://feedbackassistant.apple.com/feedback/9381783
Comment 2 Sam Sneddon [:gsnedders] 2021-11-15 04:25:40 PST
rdar://80958449

> According to the w3c specification "rect" should return coordinates relative to the browsing context

No, it's "relative to the current browsing context’s document element"

WPT has some failing tests, though not scrolling first: https://wpt.fyi/results/webdriver/tests/get_element_rect/get.py?label=experimental&label=master&aligned