You are here

public function NodeElement::selectOption in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/behat/mink/src/Element/NodeElement.php \Behat\Mink\Element\NodeElement::selectOption()

Selects specified option for select field or specified radio button in the group.

If the current node is a select box, this selects the option found by its value or its text. If the current node is a radio button, this selects the radio button with the given value in the radio button group of the current node.

Calling this method on any other elements is not allowed.

Parameters

string $option:

Boolean $multiple whether the option should be added to the selection for multiple selects:

Throws

ElementNotFoundException when the option is not found in the select box

File

vendor/behat/mink/src/Element/NodeElement.php, line 223

Class

NodeElement
Page element node.

Namespace

Behat\Mink\Element

Code

public function selectOption($option, $multiple = false) {
  if ('select' !== $this
    ->getTagName()) {
    $this
      ->getDriver()
      ->selectOption($this
      ->getXpath(), $option, $multiple);
    return;
  }
  $opt = $this
    ->find('named', array(
    'option',
    $option,
  ));
  if (null === $opt) {
    throw new ElementNotFoundException($this
      ->getDriver(), 'select option', 'value|text', $option);
  }
  $this
    ->getDriver()
    ->selectOption($this
    ->getXpath(), $opt
    ->getValue(), $multiple);
}