Created
January 11, 2014 00:59
-
-
Save alnutile/8365581 to your computer and use it in GitHub Desktop.
Dealing with HTML that has multiple form fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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
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
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