You are here

public function BrowserKitDriver::isChecked in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php \Behat\Mink\Driver\BrowserKitDriver::isChecked()

Checks whether checkbox or radio button located by it's XPath query is checked.

Parameters

string $xpath:

Return value

Boolean

Throws

UnsupportedDriverActionException When operation not supported by the driver

DriverException When the operation cannot be done

Overrides CoreDriver::isChecked

See also

\Behat\Mink\Element\NodeElement::isChecked

File

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

Class

BrowserKitDriver
Symfony2 BrowserKit driver.

Namespace

Behat\Mink\Driver

Code

public function isChecked($xpath) {
  $field = $this
    ->getFormField($xpath);
  if (!$field instanceof ChoiceFormField || 'select' === $field
    ->getType()) {
    throw new DriverException(sprintf('Impossible to get the checked state of the element with XPath "%s" as it is not a checkbox or radio input', $xpath));
  }
  if ('checkbox' === $field
    ->getType()) {
    return $field
      ->hasValue();
  }
  $radio = $this
    ->getCrawlerNode($this
    ->getFilteredCrawler($xpath));
  return $radio
    ->getAttribute('value') === $field
    ->getValue();
}