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

Breadcrumb

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

function Selenium2Driver::selectRadioValue

Selects a value in a radio button group

Parameters

Element $element An element referencing one of the radio buttons of the group:

string $value The value to select:

Throws

DriverException when the value cannot be found

2 calls to Selenium2Driver::selectRadioValue()
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 1187

Class

Selenium2Driver
Selenium2 driver.

Namespace

Behat\Mink\Driver

Code

private function selectRadioValue(Element $element, string $value) : void {
    // short-circuit when we already have the right button of the group to avoid XPath queries
    if ($element->attribute('value') === $value) {
        $element->click();
        return;
    }
    $name = $element->attribute('name');
    if (!$name) {
        throw new DriverException(sprintf('The radio button does not have the value "%s"', $value));
    }
    $formId = $element->attribute('form');
    try {
        if (null !== $formId) {
            $xpath = <<<'XPATH'
//form[@id=%1$s]//input[@type="radio" and not(@form) and @name=%2$s and @value = %3$s]
|
//input[@type="radio" and @form=%1$s and @name=%2$s and @value = %3$s]
XPATH;
            $xpath = sprintf($xpath, $this->xpathEscaper
                ->escapeLiteral($formId), $this->xpathEscaper
                ->escapeLiteral($name), $this->xpathEscaper
                ->escapeLiteral($value));
            $input = $this->getWebDriverSession()
                ->element('xpath', $xpath);
        }
        else {
            $xpath = sprintf('./ancestor::form//input[@type="radio" and not(@form) and @name=%s and @value = %s]', $this->xpathEscaper
                ->escapeLiteral($name), $this->xpathEscaper
                ->escapeLiteral($value));
            $input = $element->element('xpath', $xpath);
        }
    } catch (NoSuchElement $e) {
        $message = sprintf('The radio group "%s" does not have an option "%s"', $name, $value);
        throw new DriverException($message, 0, $e);
    }
    $input->click();
}

API Navigation

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