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

Breadcrumb

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

function WebAssert::elementsCount

Checks that there is specified number of specific elements on the page.

Parameters

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

string|array $selector element selector:

int $count expected count:

ElementInterface|null $container document to check against:

Return value

void

Throws

ExpectationException

File

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

Class

WebAssert
Mink web assertions tool.

Namespace

Behat\Mink

Code

public function elementsCount(string $selectorType, $selector, int $count, ?ElementInterface $container = null) {
    $container = $container ?: $this->session
        ->getPage();
    $nodes = $container->findAll($selectorType, $selector);
    $message = sprintf('%d %s found on the page, but should be %d.', count($nodes), $this->getMatchingElementRepresentation($selectorType, $selector, count($nodes) !== 1), $count);
    $this->assert(intval($count) === count($nodes), $message);
}

API Navigation

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