Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this IF is needed. Instead I'm proposing to allow only these elements in method:

  • input HTML elements with specific type attribute values (already done)
  • maybe textarea elements

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, do we want to accept selects?
If we only leave in the method the "input" IF, textarea input types will be accepted by default.

// 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}
*/
Expand Down