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

Breadcrumb

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

function Selenium2Driver::selectOptionOnElement

Throws

DriverException

2 calls to Selenium2Driver::selectOptionOnElement()
Selenium2Driver::selectOption in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Selects option from select field or value in radio group located by its XPath query.
Selenium2Driver::setValue in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Sets element's value by its XPath query.

File

vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php, line 1239

Class

Selenium2Driver
Selenium2 driver.

Namespace

Behat\Mink\Driver

Code

private function selectOptionOnElement(Element $element, string $value, bool $multiple = false) : void {
    $escapedValue = $this->xpathEscaper
        ->escapeLiteral($value);
    // The value of an option is the normalized version of its text when it has no value attribute
    $optionQuery = sprintf('.//option[@value = %s or (not(@value) and normalize-space(.) = %s)]', $escapedValue, $escapedValue);
    $option = $element->element('xpath', $optionQuery);
    if ($multiple || !$element->attribute('multiple')) {
        if (!$option->selected()) {
            $option->click();
        }
        return;
    }
    // Deselect all options before selecting the new one
    $this->deselectAllOptions($element);
    $option->click();
}

API Navigation

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