Skip to content

Commit b57c052

Browse files
https://github.com/minkphp/MinkSelenium2Driver/pull/302
1 parent 5d15043 commit b57c052

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

src/Selenium2Driver.php

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,15 @@ public function setValue($xpath, $value)
682682
}
683683
}
684684

685-
$value = strval($value);
685+
# $value = strval($value);
686686

687-
if (in_array($elementName, array('input', 'textarea'))) {
688-
$existingValueLength = strlen($element->attribute('value'));
689-
$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value;
690-
}
687+
# if (in_array($elementName, array('input', 'textarea'))) {
688+
# $existingValueLength = strlen($element->attribute('value'));
689+
# $value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value;
690+
# }
691691

692-
$element->postValue(array('value' => array($value)));
692+
# $element->postValue(array('value' => array($value)));
693+
$this->postElementValue($value, $elementName, $element);
693694
// Remove the focus from the element if the field still has focus in
694695
// order to trigger the change event. By doing this instead of simply
695696
// triggering the change event for the given xpath we ensure that the
@@ -714,6 +715,25 @@ public function setValue($xpath, $value)
714715
}
715716
}
716717

718+
/**
719+
* {@inheritdoc}
720+
*/
721+
public function sendKeys($xpath, $value)
722+
{
723+
$element = $this->findElement($xpath);
724+
$elementName = strtolower($element->name());
725+
726+
if ('input' === $elementName) {
727+
$elementType = strtolower($element->attribute('type'));
728+
729+
if (in_array($elementType, array('submit', 'image', 'button', 'reset', 'checkbox', 'radio', 'file'))) {
730+
throw new DriverException(sprintf('Impossible to send keys on element with XPath "%s" as it is not a textbox', $xpath));
731+
}
732+
}
733+
734+
$this->postElementValue($value, $elementName, $element);
735+
}
736+
717737
/**
718738
* {@inheritdoc}
719739
*/
@@ -1231,4 +1251,21 @@ private function uploadFile($path)
12311251

12321252
return $remotePath;
12331253
}
1254+
1255+
/**
1256+
* @param $value
1257+
* @param $elementName
1258+
* @param $element
1259+
*/
1260+
private function postElementValue($value, $elementName, $element)
1261+
{
1262+
$value = strval($value);
1263+
1264+
if (in_array($elementName, array('input', 'textarea'))) {
1265+
$existingValueLength = strlen($element->attribute('value'));
1266+
$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value;
1267+
}
1268+
1269+
$element->postValue(array('value' => array($value)));
1270+
}
12341271
}

0 commit comments

Comments
 (0)