Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a65aa40

Browse files
committed
Fixing clicking outside of a viewport issue
1 parent 74a5cb8 commit a65aa40

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
@@ -768,6 +768,9 @@ public function click(string $xpath)
768768

769769
private function clickOnElement(Element $element): void
770770
{
771+
// Change the viewport, because Firefox can't move the mouse outside the viewport.
772+
$this->scrollIntoView($element);
773+
771774
try {
772775
// Move the mouse to the element as Selenium does not allow clicking on an element which is outside the viewport
773776
$this->getWebDriverSession()->moveto(array('element' => $element->getID()));
@@ -780,6 +783,14 @@ private function clickOnElement(Element $element): void
780783
$element->click();
781784
}
782785

786+
private function scrollIntoView(Element $element): void
787+
{
788+
$this->executeJsOnElement(
789+
$element,
790+
"arguments[0].scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' });"
791+
);
792+
}
793+
783794
public function doubleClick(string $xpath)
784795
{
785796
$this->mouseOver($xpath);
@@ -817,8 +828,13 @@ public function isVisible(string $xpath)
817828

818829
public function mouseOver(string $xpath)
819830
{
831+
$element = $this->findElement($xpath);
832+
833+
// Change the viewport, because Firefox can't move the mouse outside the viewport.
834+
$this->scrollIntoView($element);
835+
820836
$this->getWebDriverSession()->moveto(array(
821-
'element' => $this->findElement($xpath)->getID()
837+
'element' => $element->getID()
822838
));
823839
}
824840

0 commit comments

Comments
 (0)