Skip to content

Commit

Permalink
MDL-58948 behat: Chrome driver has unique xpaths
Browse files Browse the repository at this point in the history
Chrome driver has unique xpaths for clicking on all the
show more links.  So clicking on the first xpath X times
does not work.
  • Loading branch information
polothy committed Jun 28, 2017
1 parent 95ee1f6 commit 7cde2bb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/tests/behat/behat_forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,20 @@ protected function expand_all_fields() {
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) {
Expand Down

0 comments on commit 7cde2bb

Please sign in to comment.