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

Breadcrumb

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

function BrowserKitDriver::getFieldPosition

Gets the position of the field node among elements with the same name

BrowserKit uses the field name as index to find the field in its Form object. When multiple fields have the same name (checkboxes for instance), it will return an array of elements in the order they appear in the DOM.

Throws

DriverException

File

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

Class

BrowserKitDriver
Symfony BrowserKit driver.

Namespace

Behat\Mink\Driver

Code

private function getFieldPosition(\DOMElement $fieldNode) : int {
    $elements = $this->getCrawler()
        ->filterXPath('//*[@name=\'' . $fieldNode->getAttribute('name') . '\']');
    if (count($elements) > 1) {
        // more than one element contains this name !
        // so we need to find the position of $fieldNode
        foreach ($elements as $key => $element) {
            
            /** @var \DOMElement $element */
            if ($element->getNodePath() === $fieldNode->getNodePath()) {
                return $key;
            }
        }
    }
    return 0;
}

API Navigation

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