-
Notifications
You must be signed in to change notification settings - Fork 165
Add sendKeys method implementing Mink DriverInterface #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
d65b3ae
a76af96
7af9d1f
b2ca1d9
18dd694
ffc9543
6f79f95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -670,8 +670,6 @@ public function setValue($xpath, $value) | |
|
|
||
| if (in_array($elementName, array('input', 'textarea'))) { | ||
| $existingValueLength = strlen($element->attribute('value')); | ||
| // Add the TAB key to ensure we unfocus the field as browsers are triggering the change event only | ||
| // after leaving the field. | ||
| $value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value; | ||
| } | ||
|
|
||
|
|
@@ -692,6 +690,37 @@ public function setValue($xpath, $value) | |
| $this->executeJsOnElement($element, $script); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function sendKeys($xpath, $value) | ||
| { | ||
| $element = $this->findElement($xpath); | ||
| $elementName = strtolower($element->name()); | ||
|
|
||
| if ('select' === $elementName) { | ||
|
||
| // There is no sense on trying to autocomplete a select element. | ||
| throw new DriverException(sprintf('Impossible to set an auto-complete value on select element with XPath "%s"', $xpath)); | ||
| } | ||
|
|
||
| if ('input' === $elementName) { | ||
| $elementType = strtolower($element->attribute('type')); | ||
|
|
||
| if (in_array($elementType, array('submit', 'image', 'button', 'reset', 'checkbox', 'radio', 'file'))) { | ||
| throw new DriverException(sprintf('Impossible to set an auto-complete value on element with XPath "%s" as it is not a textarea or textbox', $xpath)); | ||
| } | ||
| } | ||
|
|
||
| $value = strval($value); | ||
|
|
||
| if (in_array($elementName, array('input', 'textarea'))) { | ||
| $existingValueLength = strlen($element->attribute('value')); | ||
| $value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value; | ||
| } | ||
|
|
||
| $element->postValue(array('value' => array($value))); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.