Skip to content
Open
Changes from all 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
37 changes: 33 additions & 4 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,12 @@ public function setValue(string $xpath, $value)
throw new DriverException(sprintf('Only string values can be used for a %s element.', $elementName));
}

$value = strval($value);

if (in_array($elementName, array('input', 'textarea'))) {
$existingValueLength = strlen($element->attribute('value'));
$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value;
$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . strval($value);
}

$element->postValue(array('value' => array($value)));
$this->postElementValue($value, $element);
// Remove the focus from the element if the field still has focus in
// order to trigger the change event. By doing this instead of simply
// triggering the change event for the given xpath we ensure that the
Expand All @@ -700,6 +698,28 @@ public function setValue(string $xpath, $value)
}
}

/**
* {@inheritdoc}
*/
public function sendKeys($xpath, $value)
{
$element = $this->findElement($xpath);
$elementName = strtolower($element->name());

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 send keys on element with XPath "%s" as it is not a textbox', $xpath));
}
}

$this->postElementValue($value, $element);
}

/**
* {@inheritdoc}
*/
public function check(string $xpath)
{
$element = $this->findElement($xpath);
Expand Down Expand Up @@ -1154,4 +1174,13 @@ private function uploadFile(string $path): string

return $remotePath;
}

/**
* @param string $value the value of the element
* @param Element $element the webdriver element
*/
private function postElementValue($value, $element)
{
$element->postValue(array('value' => array($value)));
}
}