Skip to content

Commit

Permalink
send-keys-1.3.1: apply re-roll of minkphp#302 https://github.com/mink…
Browse files Browse the repository at this point in the history
  • Loading branch information
miiimooo committed Dec 6, 2018
1 parent 473a9f3 commit d81b143
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,17 +652,7 @@ public function setValue($xpath, $value)
return;
}
}

$value = strval($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 . Key::TAB;
}

$element->postValue(array('value' => array($value)));
$this->postElementValue($value, $elementName, $element);
}

/**
Expand Down Expand Up @@ -695,6 +685,25 @@ public function uncheck($xpath)
$this->clickOnElement($element);
}

/**
* {@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, $elementName, $element);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -1094,4 +1103,22 @@ private function ensureInputType(Element $element, $xpath, $type, $action)
throw new DriverException(sprintf($message, $action, $xpath, $type));
}
}

/**
* @param $value
* @param $elementName
* @param $element
*/
private function postElementValue($value, $elementName, $element)
{
$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)));
}

}

0 comments on commit d81b143

Please sign in to comment.