You are here

private function BrowserKitDriver::getFieldPosition in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php \Behat\Mink\Driver\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.

Parameters

\DOMElement $fieldNode:

Return value

integer

File

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

Class

BrowserKitDriver
Symfony2 BrowserKit driver.

Namespace

Behat\Mink\Driver

Code

private function getFieldPosition(\DOMElement $fieldNode) {
  $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;
}