You are here

public function BrowserKitDriver::selectOption 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::selectOption()

Selects option from select field or value in radio group located by it's XPath query.

Parameters

string $xpath:

string $value:

Boolean $multiple:

Throws

UnsupportedDriverActionException When operation not supported by the driver

DriverException When the operation cannot be done

Overrides CoreDriver::selectOption

See also

\Behat\Mink\Element\NodeElement::selectOption

File

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

Class

BrowserKitDriver
Symfony2 BrowserKit driver.

Namespace

Behat\Mink\Driver

Code

public function selectOption($xpath, $value, $multiple = false) {
  $field = $this
    ->getFormField($xpath);
  if (!$field instanceof ChoiceFormField) {
    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 ($multiple) {
    $oldValue = (array) $field
      ->getValue();
    $oldValue[] = $value;
    $value = $oldValue;
  }
  $field
    ->select($value);
}