From fba8cbda0e8ede770f22edbb3f59c4021c308469 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 4 Dec 2020 12:54:54 +0800 Subject: [PATCH] MDL-66979: Workaround geckodriver clicking on link containing block 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. 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. --- .../BehatExtension/Element/NodeElement.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Moodle/BehatExtension/Element/NodeElement.php b/src/Moodle/BehatExtension/Element/NodeElement.php index 1c729d0..0d82987 100644 --- a/src/Moodle/BehatExtension/Element/NodeElement.php +++ b/src/Moodle/BehatExtension/Element/NodeElement.php @@ -25,6 +25,7 @@ namespace Moodle\BehatExtension\Element; use Behat\Mink\Element\NodeElement as MinkNodeElement; +use Facebook\WebDriver\Exception\NoSuchWindowException; /** * Node Element. @@ -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; + } }