function toggleCoupons(FeatureContext $world, TableNode $table) { $hash = $table->getHash(); foreach ($hash as $row) { if (isset($row['enabled'])) { $switcher = $world->find('xpath', '//a[text()="' . $row['name'] . '"]/ancestor::tr//span[contains(@class, "input-checkbox-switcher")]'); $class = $switcher->getAttribute('class'); if (strpos($class, $row['enabled']) === false) { $switcher->find('css', '.widget')->click(); } } } $world->pressButton("Save changes"); }