function SelectorsContext::setSelectionRangeFromField in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::setSelectionRangeFromField()
- 8.4 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::setSelectionRangeFromField()
- 8.6 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::setSelectionRangeFromField()
- 8.7 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::setSelectionRangeFromField()
- 9.0.x tests/features/bootstrap/SelectorsContext.php \SelectorsContext::setSelectionRangeFromField()
#vardot : Select part of the text in selected field input element.
Example #1: When I select from 0 to 5 text in "Title" field Example #2: And I select from 0 to 5 text in "Description" field.
@When /^(?:|I )select from (?P<from>\d+) to (?P<to>\d+) text in "(?P<selectedField>[^"]*)" field$/
File
- tests/
features/ bootstrap/ SelectorsContext.php, line 328
Class
- SelectorsContext
- Defines application features from the specific context.
Code
function setSelectionRangeFromField($from, $to, $selectedField) {
$field = $this
->getSession()
->getPage()
->findField($selectedField);
$fieldid = $field
->getAttribute('id');
if ($from < 0) {
$from = 0;
}
if ($to === 0) {
$to = $field
->getValue()
->length();
}
$this
->getSession()
->getDriver()
->evaluateScript('document.getElementById("' . $fieldid . '").setSelectionRange(' . $from . ',' . $to . ');');
}