Skip to content

Commit b6823ea

Browse files
committed
Fixing clicking outside of a viewport issue
1 parent a637df5 commit b6823ea

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Selenium2Driver.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ public function click(string $xpath)
761761

762762
private function clickOnElement(Element $element): void
763763
{
764+
// Change the viewport, because Firefox can't move the mouse outside the viewport.
765+
$this->scrollIntoView($element);
766+
764767
try {
765768
// Move the mouse to the element as Selenium does not allow clicking on an element which is outside the viewport
766769
$this->getWebDriverSession()->moveto(array('element' => $element->getID()));
@@ -773,6 +776,14 @@ private function clickOnElement(Element $element): void
773776
$element->click();
774777
}
775778

779+
private function scrollIntoView(Element $element): void
780+
{
781+
$this->executeJsOnElement(
782+
$element,
783+
"arguments[0].scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' });"
784+
);
785+
}
786+
776787
public function doubleClick(string $xpath)
777788
{
778789
$this->mouseOver($xpath);
@@ -810,8 +821,13 @@ public function isVisible(string $xpath)
810821

811822
public function mouseOver(string $xpath)
812823
{
824+
$element = $this->findElement($xpath);
825+
826+
// Change the viewport, because Firefox can't move the mouse outside the viewport.
827+
$this->scrollIntoView($element);
828+
813829
$this->getWebDriverSession()->moveto(array(
814-
'element' => $this->findElement($xpath)->getID()
830+
'element' => $element->getID()
815831
));
816832
}
817833

0 commit comments

Comments
 (0)