diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 3f2d1c39..9cb31c1a 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -768,6 +768,9 @@ public function click(string $xpath) private function clickOnElement(Element $element): void { + // Change the viewport, because Firefox can't move the mouse outside the viewport. + $this->scrollIntoView($element); + try { // Move the mouse to the element as Selenium does not allow clicking on an element which is outside the viewport $this->getWebDriverSession()->moveto(array('element' => $element->getID())); @@ -780,6 +783,14 @@ private function clickOnElement(Element $element): void $element->click(); } + private function scrollIntoView(Element $element): void + { + $this->executeJsOnElement( + $element, + "arguments[0].scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' });" + ); + } + public function doubleClick(string $xpath) { $this->mouseOver($xpath); @@ -817,8 +828,13 @@ public function isVisible(string $xpath) public function mouseOver(string $xpath) { + $element = $this->findElement($xpath); + + // Change the viewport, because Firefox can't move the mouse outside the viewport. + $this->scrollIntoView($element); + $this->getWebDriverSession()->moveto(array( - 'element' => $this->findElement($xpath)->getID() + 'element' => $element->getID() )); }