Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. WebAssert.php

function WebAssert::elementTextContains

Checks that specific element contains text.

Parameters

string $selectorType element selector type (css, xpath):

string|array $selector element selector:

string $text expected text:

Return value

void

Throws

ElementTextException

ElementNotFoundException

File

vendor/behat/mink/src/WebAssert.php, line 507

Class

WebAssert
Mink web assertions tool.

Namespace

Behat\Mink

Code

public function elementTextContains(string $selectorType, $selector, string $text) {
    $element = $this->elementExists($selectorType, $selector);
    $actual = $element->getText();
    $regex = '/' . preg_quote($text, '/') . '/ui';
    $message = sprintf('The text "%s" was not found in the text of the %s.', $text, $this->getMatchingElementRepresentation($selectorType, $selector));
    $this->assertElementText((bool) preg_match($regex, $actual), $message, $element);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal