From d9335cc292ba9c0c9fa254a6486a8dee1c477442 Mon Sep 17 00:00:00 2001 From: "Johnny.H" Date: Mon, 20 Feb 2023 14:37:56 +0800 Subject: [PATCH] add `scroll_element_into_view` workaround for firefox "MoveTargetOutOfBoundsException" error --- src/SeleniumLibrary/keywords/element.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SeleniumLibrary/keywords/element.py b/src/SeleniumLibrary/keywords/element.py index 51e3710cc..b7129a0e7 100644 --- a/src/SeleniumLibrary/keywords/element.py +++ b/src/SeleniumLibrary/keywords/element.py @@ -22,7 +22,7 @@ from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from selenium.webdriver.remote.webelement import WebElement - +from selenium.common.exceptions import MoveTargetOutOfBoundsException from SeleniumLibrary.base import LibraryComponent, keyword from SeleniumLibrary.errors import ElementNotFound from SeleniumLibrary.utils.types import type_converter @@ -747,7 +747,11 @@ def scroll_element_into_view(self, locator: Union[WebElement, str]): element = self.find_element(locator) # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater. element = _unwrap_eventfiring_element(element) - ActionChains(self.driver).move_to_element(element).perform() + try: + ActionChains(self.driver).move_to_element(element).perform() + except MoveTargetOutOfBoundsException as e: + self.debug(f"Move to element with error: {e}.") + self.driver.execute_script("arguments[0].scrollIntoView(true);", element) @keyword def drag_and_drop(