Skip to content

Commit

Permalink
Fixing clicking outside of a viewport issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Oct 31, 2024
1 parent 74a5cb8 commit a65aa40
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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);
Expand Down Expand Up @@ -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()
));
}

Expand Down

0 comments on commit a65aa40

Please sign in to comment.