Skip to content

Commit

Permalink
MDL-66979: Workaround geckodriver clicking on link containing block
Browse files Browse the repository at this point in the history
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
  • Loading branch information
andrewnicols committed Dec 4, 2020
1 parent 1bd8778 commit fba8cbd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Moodle/BehatExtension/Element/NodeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Moodle\BehatExtension\Element;

use Behat\Mink\Element\NodeElement as MinkNodeElement;
use Facebook\WebDriver\Exception\NoSuchWindowException;

/**
* Node Element.
Expand All @@ -46,7 +47,20 @@ public function click() {
$this->ensure_node_is_in_viewport();
}

parent::click();
try {
parent::click();
} catch (ElementNotInteractableException $e) {
// There is a bug in Geckodriver which means that it is unable to click any link which contains a block
// level node. See https://github.com/mozilla/geckodriver/issues/653.
// The workaround is to click on it's first descendant instead.
if ($child = $this->find('xpath', './*[1]')) {
$child->click();

return;
}

throw $e;
}
}


Expand Down

0 comments on commit fba8cbd

Please sign in to comment.