Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created January 11, 2014 00:59
Show Gist options
  • Save alnutile/8365581 to your computer and use it in GitHub Desktop.
Save alnutile/8365581 to your computer and use it in GitHub Desktop.
Dealing with HTML that has multiple form fields
/**
* @hidden
*
* @Then /^I fill in the form field with id "([^"]*)" number "([^"]*)" with the value of "([^"]*)"$/
*/
public function fillInTheFormFieldWithIDNumberWithTheValueOf($arg1, $arg2, $arg3)
{
$arg = $arg2 - 1; //most users do not start at 0
$form_field = $this->getMainContext()->getSession()->getPage()->findAll('css', $arg1);
if($form_field) {
$form_field[$arg]->setValue($arg3);
} else {
throw new Exception('Form Element not found');
}
}
@stof
Copy link

stof commented Jan 13, 2014

Having multiple elements with the same id is invalid HTML. It is better to fix it rather than finding a way to make Behat and Mink accept it IMO

@jeff1985
Copy link

@stof
i think the name of the method is misleading. the "id" is $arg1 and will be used as css selector in the code.
this could be something as simple as "input" and would match any element on the page without violating any HTML rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment