scroll elements into view before moving the pointer

The pointer is moved to viewport coordinates, so an element below the fold produced a target outside the window and the driver raised MoveTargetOutOfBoundsException. Observed on the daily set opener during a scheduled run. Also clamps the bezier path to the viewport.
This commit is contained in:
mardausdennis
2026-08-25 13:14:39 +02:00
parent 9842d608c8
commit 2773018161
+20 -1
View File
@@ -282,11 +282,21 @@ class MouseUtils:
start_time = time.monotonic()
end_time = start_time + move_time
# The distorted bezier path can overshoot the window edge, which the
# driver rejects, so keep every sampled point inside the viewport.
viewport = self.driver.execute_script(
"return [window.innerWidth, window.innerHeight];"
)
max_x, max_y = int(viewport[0]) - 2, int(viewport[1]) - 2
while (current_time := time.monotonic()) < end_time:
t = current_time - start_time
point = path_function(t)
point = (max(0, point[0]), max(0, point[1])) # ensure the point is not negative
point = (
min(max(0, point[0]), max_x),
min(max(0, point[1]), max_y)
)
actions = ActionBuilder(self.driver, duration=0)
actions.pointer_action.move_to_location(point[0], point[1])
@@ -302,6 +312,15 @@ class MouseUtils:
def move_to_element(self, element: WebElement, visualize: bool=True):
# The pointer is moved to viewport coordinates, so an element below the
# fold yields a target outside the window and the driver rejects the move
# with MoveTargetOutOfBoundsException. Bring it into view first.
self.driver.execute_script(
"arguments[0].scrollIntoView({block: 'center', inline: 'center'});",
element
)
time.sleep(0.4)
current_mouse_position = self.get_current_mouse_position()
rect = self.driver.execute_script("""