You are here

public function FeatureContext::iClickTheLinkWithText in Open Social 8

Same name and namespace in other branches
  1. 8.2 tests/behat/features/bootstrap/FeatureContext.php \FeatureContext::iClickTheLinkWithText()

@When I click the xth :position link with the text :locator

File

tests/behat/features/bootstrap/FeatureContext.php, line 247

Class

FeatureContext
Defines application features from the specific context.

Code

public function iClickTheLinkWithText($position, $locator) {
  $session = $this
    ->getSession();
  $links = $session
    ->getPage()
    ->findAll('named', array(
    'link',
    $locator,
  ));
  $count = 1;
  foreach ($links as $link) {
    if ($count == $position) {

      // Now click the element.
      $link
        ->click();
      return;
    }
    $count++;
  }
  throw new \InvalidArgumentException(sprintf('Element not found with the locator: "%s"', $locator));
}