From c5d7a742a23cd962883854ad3d67b49c02f768f5 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Fri, 16 Aug 2024 14:08:23 +1000 Subject: [PATCH] Fixed scrolling an element into view only if it is not within a view. --- src/Selenium2Driver.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 463479be..5185d7c4 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -953,8 +953,19 @@ public function mouseOver(string $xpath) private function scrollElementIntoView(Element $element): void { $script = <<= 0 && + rect.left >= 0 && + rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && + rect.right <= (window.innerWidth || document.documentElement.clientWidth) + ); + + if (!inView) { + e.scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' }); + rect = e.getBoundingClientRect(); + } + return {'x': rect.left, 'y': rect.top}; JS;