1919class WebDriverActions {
2020
2121 protected $ driver ;
22+ protected $ keyboard ;
2223 protected $ mouse ;
2324 protected $ action ;
2425
25- // TODO: add keyboard actions
26- // protected $keyboard;
27-
2826 public function __construct (WebDriver $ driver ) {
2927 $ this ->driver = $ driver ;
28+ $ this ->keyboard = $ driver ->getKeyboard ();
3029 $ this ->mouse = $ driver ->getMouse ();
3130 $ this ->action = new WebDriverCompositeAction ();
3231 }
@@ -137,6 +136,7 @@ public function moveToElement(WebDriverElement $element,
137136 $ this ->action ->addAction (new WebDriverMoveToOffsetAction (
138137 $ this ->mouse , $ element , $ x_offset , $ y_offset
139138 ));
139+ return $ this ;
140140 }
141141
142142 /**
@@ -149,4 +149,45 @@ public function release(WebDriverElement $element = null) {
149149 );
150150 return $ this ;
151151 }
152+
153+ /**
154+ * Press a key on keyboard.
155+ * If $element is provided, focus on that element first.
156+ *
157+ * @see WebDriverKeys for special keys like CONTROL, ALT, etc.
158+ */
159+ public function keyDown (WebDriverElement $ element = null , $ key ) {
160+ $ this ->action ->addAction (
161+ new WebDriverKeyDownAction ($ this ->keyboard , $ this ->mouse , $ element , $ key )
162+ );
163+ return $ this ;
164+ }
165+
166+ /**
167+ * Release a key on keyboard.
168+ * If $element is provided, focus on that element first.
169+ *
170+ * @see WebDriverKeys for special keys like CONTROL, ALT, etc.
171+ */
172+ public function keyUp (WebDriverElement $ element = null , $ key ) {
173+ $ this ->action ->addAction (
174+ new WebDriverKeyUpAction ($ this ->keyboard , $ this ->mouse , $ element , $ key )
175+ );
176+ return $ this ;
177+ }
178+
179+ /**
180+ * Send keys by keyboard.
181+ * If $element is provided, focus on that element first.
182+ *
183+ * @see WebDriverKeys for special keys like CONTROL, ALT, etc.
184+ */
185+ public function sendKeys (WebDriverElement $ element = null , $ keys ) {
186+ $ this ->action ->addAction (
187+ new WebDriverSendKeysAction (
188+ $ this ->keyboard , $ this ->mouse , $ element , $ keys
189+ )
190+ );
191+ return $ this ;
192+ }
152193}
0 commit comments