public function TestSubContext::clickNthLink in Panopoly 7
Same name and namespace in other branches
- 8.2 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::clickNthLink()
@When /^I click the (?P<count>\d+)(?:st|nd|rd|th) "(?P<link>[^"]*)" in the "(?P<region>[^"]*)" region$/
File
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 1101 - Provide Behat step-definitions for generic Panopoly tests.
Class
Code
public function clickNthLink($count, $link, $region) {
$session = $this
->getSession();
$region = $session
->getPage()
->find('region', $region);
// We index from zero, rather than one.
$index = $count - 1;
foreach ($region
->findAll('xpath', '//a[text()="' . $link . '"]') as $element) {
if ($index == 0) {
$element
->click();
return;
}
elseif ($index < 0) {
break;
}
else {
$index--;
}
}
throw new \Exception(sprintf("Cannot find link with text '%s' and index %d", $link, $count));
}