mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8461 from creative-commoners/pulls/4.3/unbelabelable-dom-skills
NEW Adding a helper to find a form field by label content (Behat)
This commit is contained in:
commit
1d1cf6882d
@ -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 "([^"]*)"$/
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user