Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NodeElement.php

function 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:

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

Return value

void

Throws

ElementNotFoundException when the option is not found in the select box

File

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

Class

NodeElement
Page element node.

Namespace

Behat\Mink\Element

Code

public function selectOption(string $option, bool $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);
    }
    $optionValue = $opt->getValue();
    \assert(\is_string($optionValue), 'The value of an option element should always be a string.');
    $this->getDriver()
        ->selectOption($this->getXpath(), $optionValue, $multiple);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal