public function VarbaseContext::iSelectTheRadioButton in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 9.0.x
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iSelectTheRadioButton()
- 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iSelectTheRadioButton()
- 8.5 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iSelectTheRadioButton()
- 8.6 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iSelectTheRadioButton()
- 8.7 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iSelectTheRadioButton()
Select a radio button.
Varbase Context #varbase.
Example #1: When I select the "Male" radio button Example #2: And I select the "Male" radio button
@When /^I select the "([^"]*)" radio button$/
File
- tests/
features/ bootstrap/ VarbaseContext.php, line 1406
Class
- VarbaseContext
- Defines application features from the specific context.
Code
public function iSelectTheRadioButton($labelText) {
// Find the label by its text, then use that to get the radio item's ID.
$radioId = NULL;
/** @var $label NodeElement */
foreach ($this
->getSession()
->getPage()
->findAll('css', 'label') as $label) {
if ($labelText === $label
->getText()) {
if ($label
->hasAttribute('for')) {
$radioId = $label
->getAttribute('for');
break;
}
else {
throw new \Exception("Radio button's label needs the 'for' attribute to be set");
}
}
}
if (!$radioId) {
throw new \InvalidArgumentException("Label '{$labelText}' not found.");
}
// Now use the ID to retrieve the button and click it.
// @var NodeElement $radioButton.
$radioButton = $this
->getSession()
->getPage()
->find('css', "#{$radioId}");
if (!$radioButton) {
throw new \Exception("{$labelText} radio button not found.");
}
$this
->getSession()
->getPage()
->fillField($radioId, $radioButton
->getAttribute('value'));
}