Returns form field from XPath query.

@param string $xpath

@return FormField

@throws DriverException
329394
protected function getFormField($xpath)
    {
        $fieldNode = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
        $fieldName = str_replace('[]', '', $fieldNode->getAttribute('name'));

        $formNode = $this->getFormNode($fieldNode);
        $formId = $this->getFormNodeId($formNode);

        if (!isset($this->forms[$formId])) {
            $this->forms[$formId] = new Form($formNode, $this->getCurrentUrl());
        }

        if (is_array($this->forms[$formId][$fieldName])) {
            return $this->forms[$formId][$fieldName][$this->getFieldPosition($fieldNode)];
        }

        return $this->forms[$formId][$fieldName];
    }
91439
protected function findElementXpaths($xpath) {
    $elements = $this->browser->find("xpath", $xpath);
    $nodeXPaths = array();

    if (!isset($elements["ids"])) {
      return array();
    }

    foreach ($elements["ids"] as $i => $elementId) {
      $nodeXPaths[] = sprintf('(%s)[%d]', $xpath, $i + 1);
    }
    return $nodeXPaths;
  }
1053951
public function xpathOne($path)
    {
        $result = $this->xpath($path);
        if(is_array($result))
            return current($result);

        return $result;

    }
247557
private function createFieldsElement($xml)
    {
        $fields = $xml->createElement('fields');

        foreach ($this->fields as $f) {
            $fields->appendChild($this->createFieldElement($xml, $f));
        }

        return $fields;
    }
398123
public function element(string $selector): ?Element
    {
        $element = $this->resolver->find($selector);
        return self::convertElement($element, $this->driver);
    }
794163
public function xpath($path) {
    if ($path{0} === '/') {
      $this->rewind();
      if ($this->valid()) {
        return $this->current()->xpath($path);
      }
      return $this->_getEmptyElement();
    }

    return $this->_eachGetIterator('xpath', $path);
  }
362578
private static function getXml(\SimpleXMLElement $element) {
        $getTest = $element->asXML();
        if ($getTest === false) {
            $getTest = '';
        }

        return $getTest;
    }
1113149
public function selectOption($xpath, $value, $multiple = false) {
    $element = $this->findElement($xpath, 1);
    $tagName = strtolower($this->browser->tagName($element["page_id"], $element["ids"][0]));
    $attributes = $this->browser->attributes($element["page_id"], $element["ids"][0]);

    if (!in_array($tagName, array("input", "select"))) {
      throw new DriverException(sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath));
    }

    if ($tagName === "input" && $attributes["type"] != "radio") {
      throw new DriverException(sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath));
    }

    return $this->browser->selectOption($element["page_id"], $element["ids"][0], $value, $multiple);
  }
712620
public function getElement($path)
    {
        $found = null;

        foreach ($this->getElements() as $element) {
            if ($element instanceof ElementsInterface) {
                if (! is_null($found = $element->getElement($path))) {
                    return $found;
                }
            }

            if ($element instanceof NamedFormElement && $element->getPath() == $path) {
                return $element;
            }
        }
    }
1138862
public function prepend($xpath, $prefix)
    {
        $expressions = array();

        // If the xpath prefix contains a union we need to wrap it in parentheses.
        if (preg_match(self::UNION_PATTERN, $prefix)) {
            $prefix = '('.$prefix.')';
        }

        // Split any unions into individual expressions.
        foreach ($this->splitUnionParts($xpath) as $expression) {
            $expression = trim($expression);
            $parenthesis = '';

            // If the union is inside some braces, we need to preserve the opening braces and apply
            // the prefix only inside it.
            if (preg_match('/^[\(\s*]+/', $expression, $matches)) {
                $parenthesis = $matches[0];
                $expression = substr($expression, strlen($parenthesis));
            }

            // add prefix before element selector
            if (0 === strpos($expression, '/')) {
                $expression = $prefix.$expression;
            } else {
                $expression = $prefix.'/'.$expression;
            }
            $expressions[] = $parenthesis.$expression;
        }

        return implode(' | ', $expressions);
    }
1311761
public function isSelected($xpath) {
    $elements = $this->findElement($xpath, 1);
    $javascript = $this->javascriptTemplateRender("is_selected.js.twig", array("xpath" => $xpath));
    $tagName = $this->browser->tagName($elements["page_id"], $elements["ids"][0]);
    if (strcmp(strtolower($tagName), "option") !== 0) {
      throw new DriverException("Can not assert on element that is not an option");
    }

    return $this->browser->evaluate($javascript);
  }
284735
public function xpath(string $xpath_query)
    {
        $result = $this->createChildInstance();

        if (isset($this->document)) {
            $result->xpath_query = $xpath_query;

            if (isset($this->root_instance) || isset($this->xpath_query)) {  // all nodes as context
                foreach ($this->nodes as $node) {
                    if ($result_node_list = $this->xpathQuery('.'.$xpath_query, $node)) {
                        $result->loadDomNodeList($result_node_list);
                    }
                }
            } else { // whole document
                if ($result_node_list = $this->xpathQuery($xpath_query)) {
                    $result->loadDomNodeList($result_node_list);
                }
            }
        }

        return $result;
    }
57669
private function injectNsToXpathQuery($xpath, $ns)
    {
        $literals = array();
        $offset = 0;
        $keywords = array(
            '$$_AND_$$' => 'and',
            '$$_OR_$$' => 'or'
        );

        // identified escaped backslashes
        $extractor = function($m) use (&$literals, &$offset) {
            $placeholder = '$$_' . $offset . '_$$';
            $literals[$placeholder] = $m[0];
            $offset++;

            return $placeholder;
        };

        // Extract literals
        $modified = preg_replace_callback('~(\'|").*?\1~is', $extractor, $xpath);
        $modified = preg_replace_callback('~\b(and|or)\b~i', function($match) {
            return '$$_' . strtoupper(trim($match[1])) . '_$$';
        }, $modified);

        // Now find all unqualified names and prefix them with the namespace
        $modified = preg_replace('~(?<!@|:)\b[a-z][a-z0-9_-]*\b(?!:|\s*\()~i', $ns . ':$0', $modified);

        // re-insert keywords and literals
        $modified = strtr($modified, $keywords);
        $modified = strtr($modified, $literals);

        return $modified;
    }
988311
public function isChecked($xpath) {
    $this->findElement($xpath, 1);
    $javascript = $this->javascriptTemplateRender("is_checked.js.twig", array("xpath" => $xpath));
    $checked = $this->browser->evaluate($javascript);

    if ($checked === null) {
      throw new DriverException("Can not check when the element is not checkbox or radio");
    }

    return $checked;
  }
378821
public function check($xpath) {
    $this->inputCheckableControl($xpath);
    $javascript = $this->javascriptTemplateRender("check_element.js.twig", array("xpath" => $xpath, "check" => "true"));
    $this->browser->evaluate($javascript);
  }
189893
protected function getConfigFromXmlFile($filepath)
	{
		$dom = new DOMDocument;
		$dom->loadXML(file_get_contents($filepath), LIBXML_NOCDATA);

		return $this->getElementConfig($dom->documentElement);
	}
591764
private function getFilteredCrawler($xpath)
    {
        if (!count($crawler = $this->getCrawler()->filterXPath($xpath))) {
            throw new DriverException(sprintf('There is no element matching XPath "%s"', $xpath));
        }

        return $crawler;
    }