NEW Adding a helper to find a form field by label content

This commit is contained in:
Guy Marriott 2018-10-08 14:28:10 +13:00
parent 36b1066413
commit 2775895d03
No known key found for this signature in database
GPG Key ID: A80F9ACCB86D3DA7

View File

@ -310,11 +310,38 @@ JS;
{
$locator = $this->fixStepArgument($locator);
$page = $this->getSession()->getPage();
// Searching by name is usually good...
$element = $page->find('css', 'textarea.htmleditor[name=\'' . $locator . '\']');
if ($element === null) {
$element = $this->findInputByLabelContent($locator);
}
assertNotNull($element, sprintf('HTML field "%s" not found', $locator));
return $element;
}
protected function findInputByLabelContent($locator)
{
$page = $this->getSession()->getPage();
$label = $page->findAll('xpath', sprintf('//label[contains(text(), \'%s\')]', $locator));
if (empty($label)) {
return null;
}
assertCount(1, $label, sprintf(
'Found more than one element containing the phrase "%s".',
$locator
));
$label = array_shift($label);
$fieldId = $label->getAttribute('for');
return $page->find('css', '#' . $fieldId);
}
/**
* @Given /^the "([^"]*)" field ((?:does not have)|(?:has)) property "([^"]*)"$/
*/