Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use nearest as well in the block direction ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use the scrollIntoView method myself. I've only copied the whole line from the PHP WebDriver (see https://github.com/php-webdriver/php-webdriver/blob/11923b4ba312fc9d137266ae67438be65d4d500f/lib/Remote/RemoteWebElement.php#L249 ). I trust that they know what's right here.

);
}

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