Skip to content

Commit

Permalink
Fixed scrolling an element into view only if it is not within a view.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Aug 16, 2024
1 parent 145fe8e commit c5d7a74
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,19 @@ public function mouseOver(string $xpath)
private function scrollElementIntoView(Element $element): void {
$script = <<<JS
var e = arguments[0];
e.scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' });
var rect = e.getBoundingClientRect();
var inView = (
rect.top >= 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;

Expand Down

0 comments on commit c5d7a74

Please sign in to comment.