diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 229b5c7e62b..f7e09b373bb 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -148,13 +148,20 @@ class behat_forms extends behat_base { return; } - // Funny thing about this, with findAll() we specify a pattern and each element matching the pattern is added to the array - // with of xpaths with a [0], [1]... sufix, but when we click on an element it does not matches the specified xpath - // anymore (now is a "Show less..." link) so [1] becomes [0], that's why we always click on the first XPath match, - // will be always the next one. - $iterations = count($showmores); - for ($i = 0; $i < $iterations; $i++) { - $showmores[0]->click(); + if ($this->getSession()->getDriver() instanceof \DMore\ChromeDriver\ChromeDriver) { + // Chrome Driver produces unique xpaths for each element. + foreach ($showmores as $showmore) { + $showmore->click(); + } + } else { + // Funny thing about this, with findAll() we specify a pattern and each element matching the pattern + // is added to the array with of xpaths with a [0], [1]... sufix, but when we click on an element it + // does not matches the specified xpath anymore (now is a "Show less..." link) so [1] becomes [0], + // that's why we always click on the first XPath match, will be always the next one. + $iterations = count($showmores); + for ($i = 0; $i < $iterations; $i++) { + $showmores[0]->click(); + } } } catch (ElementNotFoundException $e) {