@@ -652,17 +652,7 @@ public function setValue($xpath, $value)
652652 return ;
653653 }
654654 }
655-
656- $ value = strval ($ value );
657-
658- if (in_array ($ elementName , array ('input ' , 'textarea ' ))) {
659- $ existingValueLength = strlen ($ element ->attribute ('value ' ));
660- // Add the TAB key to ensure we unfocus the field as browsers are triggering the change event only
661- // after leaving the field.
662- $ value = str_repeat (Key::BACKSPACE . Key::DELETE , $ existingValueLength ) . $ value . Key::TAB ;
663- }
664-
665- $ element ->postValue (array ('value ' => array ($ value )));
655+ $ this ->postElementValue ($ value , $ elementName , $ element );
666656 }
667657
668658 /**
@@ -695,6 +685,25 @@ public function uncheck($xpath)
695685 $ this ->clickOnElement ($ element );
696686 }
697687
688+ /**
689+ * {@inheritdoc}
690+ */
691+ public function sendKeys ($ xpath , $ value )
692+ {
693+ $ element = $ this ->findElement ($ xpath );
694+ $ elementName = strtolower ($ element ->name ());
695+
696+ if ('input ' === $ elementName ) {
697+ $ elementType = strtolower ($ element ->attribute ('type ' ));
698+
699+ if (in_array ($ elementType , array ('submit ' , 'image ' , 'button ' , 'reset ' , 'checkbox ' , 'radio ' , 'file ' ))) {
700+ throw new DriverException (sprintf ('Impossible to send keys on element with XPath "%s" as it is not a textbox ' , $ xpath ));
701+ }
702+ }
703+
704+ $ this ->postElementValue ($ value , $ elementName , $ element );
705+ }
706+
698707 /**
699708 * {@inheritdoc}
700709 */
@@ -1094,4 +1103,22 @@ private function ensureInputType(Element $element, $xpath, $type, $action)
10941103 throw new DriverException (sprintf ($ message , $ action , $ xpath , $ type ));
10951104 }
10961105 }
1106+
1107+ /**
1108+ * @param $value
1109+ * @param $elementName
1110+ * @param $element
1111+ */
1112+ private function postElementValue ($ value , $ elementName , $ element )
1113+ {
1114+ $ value = strval ($ value );
1115+
1116+ if (in_array ($ elementName , array ('input ' , 'textarea ' ))) {
1117+ $ existingValueLength = strlen ($ element ->attribute ('value ' ));
1118+ $ value = str_repeat (Key::BACKSPACE . Key::DELETE , $ existingValueLength ) . $ value ;
1119+ }
1120+
1121+ $ element ->postValue (array ('value ' => array ($ value )));
1122+ }
1123+
10971124}
0 commit comments