From 922049aa019db477d1daaf887ae098612165d6a0 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 16 Jul 2024 14:34:47 +0100 Subject: [PATCH 1/2] Move mouse in W3C and non-W3C mode before clicking --- src/Selenium2Driver.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 058af02c..3f87b638 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -843,14 +843,10 @@ public function click(string $xpath) private function clickOnElement(Element $element): void { - if ($this->isW3C()) { - $element->click(); - } - else { - // 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())); - $element->click(); - } + // Move the mouse to the element as Selenium does not allow clicking on an element which is outside the viewport + $this->doMouseOver($element); + + $element->click(); } public function doubleClick(string $xpath) @@ -938,6 +934,11 @@ public function isVisible(string $xpath) } public function mouseOver(string $xpath) + { + $this->doMouseOver($this->findElement($xpath)); + } + + private function doMouseOver(Element $element) { if ($this->isW3C()) { $actions = array( @@ -947,7 +948,7 @@ public function mouseOver(string $xpath) 'id' => 'mouse1', 'parameters' => ['pointerType' => 'mouse'], 'actions' => [ - ['type' => 'pointerMove', 'duration' => 0, 'origin' => [Element::WEB_ELEMENT_ID => $this->findElement($xpath)->getID()], 'x' => 0, 'y' => 0], + ['type' => 'pointerMove', 'duration' => 0, 'origin' => [Element::WEB_ELEMENT_ID => $element->getID()], 'x' => 0, 'y' => 0], ], ], ], @@ -957,7 +958,7 @@ public function mouseOver(string $xpath) } else { $this->getWebDriverSession()->moveto(array( - 'element' => $this->findElement($xpath)->getID() + 'element' => $element->getID() )); } } From bcca6a004b27eb0ed3ac24b1fae72c503067f611 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 17 Jul 2024 10:18:56 +0100 Subject: [PATCH 2/2] Add return type --- src/Selenium2Driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 3f87b638..cb59be07 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -938,7 +938,7 @@ public function mouseOver(string $xpath) $this->doMouseOver($this->findElement($xpath)); } - private function doMouseOver(Element $element) + private function doMouseOver(Element $element): void { if ($this->isW3C()) { $actions = array(