You are here

protected function ContextualLinkClickTrait::clickContextualLink in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait::clickContextualLink()
  2. 9 core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait::clickContextualLink()

Clicks a contextual link.

Parameters

string $selector: The selector for the element that contains the contextual link.

string $link_locator: The link id, title, or text.

bool $force_visible: If true then the button will be forced to visible so it can be clicked.

File

core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php, line 20

Class

ContextualLinkClickTrait
Functions for testing contextual links.

Namespace

Drupal\Tests\contextual\FunctionalJavascript

Code

protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->waitFor(10, function () use ($page, $selector) {
    return $page
      ->find('css', "{$selector} .contextual-links");
  });
  if ($force_visible) {
    $this
      ->toggleContextualTriggerVisibility($selector);
  }
  $element = $this
    ->getSession()
    ->getPage()
    ->find('css', $selector);
  $element
    ->find('css', '.contextual button')
    ->press();
  $element
    ->findLink($link_locator)
    ->click();
  if ($force_visible) {
    $this
      ->toggleContextualTriggerVisibility($selector);
  }
}