Skip to content

Commit

Permalink
Move mouse in W3C and non-W3C mode before clicking
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpott committed Jul 16, 2024
1 parent 5f9ecc2 commit 922049a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -947,7 +948,7 @@ public function mouseOver(string $xpath)
'id' => 'mouse1',

Check failure on line 948 in src/Selenium2Driver.php

View workflow job for this annotation

GitHub Actions / Static analysis

Method Behat\Mink\Driver\Selenium2Driver::doMouseOver() has no return type specified.
'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],
],
],
],
Expand All @@ -957,7 +958,7 @@ public function mouseOver(string $xpath)
}
else {
$this->getWebDriverSession()->moveto(array(
'element' => $this->findElement($xpath)->getID()
'element' => $element->getID()
));
}
}
Expand Down

0 comments on commit 922049a

Please sign in to comment.