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

Breadcrumb

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

function BrowserKitDriver::getValue

Overrides CoreDriver::getValue

File

vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php, line 377

Class

BrowserKitDriver
Symfony BrowserKit driver.

Namespace

Behat\Mink\Driver

Code

public function getValue(string $xpath) {
    if (in_array($this->getAttribute($xpath, 'type'), array(
        'submit',
        'image',
        'button',
    ), true)) {
        return $this->getAttribute($xpath, 'value');
    }
    $node = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
    if ('option' === $node->tagName) {
        return $this->getOptionValue($node);
    }
    try {
        $field = $this->getFormField($xpath);
    } catch (\InvalidArgumentException $e) {
        return $this->getAttribute($xpath, 'value');
    }
    $value = $field->getValue();
    if ('select' === $node->tagName && null === $value) {
        // symfony/dom-crawler returns null as value for a non-multiple select without
        // options but we want an empty string to match browsers.
        $value = '';
    }
    return $value;
}

API Navigation

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