Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

If the checkbox element has an ID tag then you can use code below to tick it.


FeatureContext.php


use Behat\MinkExtension\Context\MinkContext;

class FeatureContext extends MinkContext
{
/**
* @Given /^The "([^"]*)" checkbox should be checked$/
*
* @param string $id The id of checkbox field.
*/
public function theCheckboxShouldBeChecked($id)
{
$page = $this->getSession()->getPage();

$isChecked = $page->find('css', 'input[type="checkbox"]:checked#' . $id);

if (! $isChecked) {
$page->find('css', '#' . $id)->click();
}
}
}