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: 14 additions & 4 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ private function clickOnElement(Element $element): void
{
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()));
$this->moveMouseToElement($element);
} catch (UnknownCommand $e) {
// If the Webdriver implementation does not support moveto (which is not part of the W3C WebDriver spec), proceed to the click
} catch (UnknownError $e) {
Expand All @@ -943,6 +943,18 @@ private function clickOnElement(Element $element): void
$element->click();
}

private function moveMouseToElement(Element $element): void
{
// Scroll the same way as php-webdriver does, because Firefox can't move the mouse outside the viewport:
// https://github.com/php-webdriver/php-webdriver/blob/1.16.0/lib/Remote/RemoteWebElement.php#L249
$this->executeJsOnElement(
$element,
"arguments[0].scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' });"

Copy link
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@stof, my point here is still valid. I think this driver should scroll to an element exactly the same as the underlying facebook web driver does for webdriver-classic-driver driver.

);

$this->getWebDriverSession()->moveto(array('element' => $element->getID()));
}

public function doubleClick(string $xpath)
{
$this->mouseOver($xpath);
Expand Down Expand Up @@ -990,9 +1002,7 @@ public function isVisible(string $xpath)

public function mouseOver(string $xpath)
{
$this->getWebDriverSession()->moveto(array(
'element' => $this->findElement($xpath)->getID()
));
$this->moveMouseToElement($this->findElement($xpath));
}

public function focus(string $xpath)
Expand Down
Loading