From 2773018161844cbc552d9c911d52c99720e62dc8 Mon Sep 17 00:00:00 2001 From: mardausdennis <71312763+mardausdennis@users.noreply.github.com> Date: Tue, 25 Aug 2026 00:57:18 +0200 Subject: [PATCH] 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. --- src/mouse_trajectory.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mouse_trajectory.py b/src/mouse_trajectory.py index d9e6489..5f47171 100644 --- a/src/mouse_trajectory.py +++ b/src/mouse_trajectory.py @@ -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("""