mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW Adding a helper to find a form field by label content
This commit is contained in:
parent
36b1066413
commit
2775895d03
@ -310,11 +310,38 @@ JS;
|
|||||||
{
|
{
|
||||||
$locator = $this->fixStepArgument($locator);
|
$locator = $this->fixStepArgument($locator);
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
|
|
||||||
|
// Searching by name is usually good...
|
||||||
$element = $page->find('css', 'textarea.htmleditor[name=\'' . $locator . '\']');
|
$element = $page->find('css', 'textarea.htmleditor[name=\'' . $locator . '\']');
|
||||||
|
|
||||||
|
if ($element === null) {
|
||||||
|
$element = $this->findInputByLabelContent($locator);
|
||||||
|
}
|
||||||
|
|
||||||
assertNotNull($element, sprintf('HTML field "%s" not found', $locator));
|
assertNotNull($element, sprintf('HTML field "%s" not found', $locator));
|
||||||
return $element;
|
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 "([^"]*)"$/
|
* @Given /^the "([^"]*)" field ((?:does not have)|(?:has)) property "([^"]*)"$/
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user