Skip to content

Commit

Permalink
https://github.com/minkphp/MinkSelenium2Driver/pull/302
Browse files Browse the repository at this point in the history
  • Loading branch information
edosenseidotcom committed Jun 11, 2022
1 parent 5d15043 commit b57c052
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,15 @@ public function setValue($xpath, $value)
}
}

$value = strval($value);
# $value = strval($value);

if (in_array($elementName, array('input', 'textarea'))) {
$existingValueLength = strlen($element->attribute('value'));
$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $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)));
# $element->postValue(array('value' => array($value)));
$this->postElementValue($value, $elementName, $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 @@ -714,6 +715,25 @@ public function setValue($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, $elementName, $element);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -1231,4 +1251,21 @@ private function uploadFile($path)

return $remotePath;
}

/**
* @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 b57c052

Please sign in to comment.