protected function WebTestBase::getSelectedItem

Get the selected value from a select field.

Parameters

$element: SimpleXMLElement select element.

Return value

The selected value or FALSE.

1 call to WebTestBase::getSelectedItem()
WebTestBase::assertFieldByXPath in drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
Asserts that a field exists in the current page by the given XPath.

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php, line 2531
Definition of Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function getSelectedItem(SimpleXMLElement $element) {
  foreach ($element
    ->children() as $item) {
    if (isset($item['selected'])) {
      return $item['value'];
    }
    elseif ($item
      ->getName() == 'optgroup') {
      if ($value = $this
        ->getSelectedItem($item)) {
        return $value;
      }
    }
  }
  return FALSE;
}