Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created January 11, 2014 00:59
Show Gist options
  • Select an option

  • Save alnutile/8365581 to your computer and use it in GitHub Desktop.

Select an option

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');
}
}
@jeff1985
Copy link
Copy Markdown

@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