DrupalWebTestCase::xpath

  1. drupal
    1. 8
    2. 7
Versions
7 protected DrupalWebTestCase::xpath($xpath, array $arguments = array())

Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.

Parameters

$xpath The xpath string to use in the search.

Return value

The return value of the xpath search. For details on the xpath string format and return values see the SimpleXML documentation, http://us.php.net/manual/function.simplexml-element-xpath.php.

Code

modules/simpletest/drupal_web_test_case.php, line 2318

<?php
protected function xpath($xpath, array $arguments = array()) {
  if ($this->parse()) {
    $xpath = $this->buildXPathQuery($xpath, $arguments);
    $result = $this->elements->xpath($xpath);
    // Some combinations of PHP / libxml versions return an empty array
    // instead of the documented FALSE. Forcefully convert any falsish values
    // to an empty array to allow foreach(...) constructions.
    return $result ? $result : array();
  }
  else {
    return FALSE;
  }
}
?>