@@ -62,6 +62,16 @@ protected function obsoleteMethods()
6262 return [];
6363 }
6464
65+ /**
66+ * Return array of chainable method/property names
67+ *
68+ * @return array
69+ */
70+ protected function chainable ()
71+ {
72+ return [];
73+ }
74+
6575 /**
6676 * Constructor
6777 *
@@ -172,6 +182,10 @@ public function __call($name, $arguments)
172182 return new $ className ($ this ->url . '/ ' . $ this ->extensions [$ name ][1 ]);
173183 }
174184
185+ if (count ($ arguments ) === 0 && array_key_exists ($ name , $ this ->chainable ())) {
186+ return call_user_func ([$ this , $ name ]);
187+ }
188+
175189 if (preg_match ('/^(get|post|delete)/ ' , $ name , $ matches )) {
176190 $ requestMethod = strtoupper ($ matches [0 ]);
177191 $ webdriverCommand = strtolower (substr ($ name , strlen ($ requestMethod )));
@@ -204,6 +218,22 @@ public function __call($name, $arguments)
204218 return $ result ['value ' ];
205219 }
206220
221+ /**
222+ * Magic method that maps property names to chainable methods
223+ *
224+ * @param string $name Property name
225+ *
226+ * @return mixed
227+ */
228+ public function __get ($ name )
229+ {
230+ if (array_key_exists ($ name , $ this ->chainable ())) {
231+ return call_user_func ([$ this , $ name ]);
232+ }
233+
234+ trigger_error ('Undefined property: ' . __CLASS__ . '::$ ' . $ name , E_USER_WARNING );
235+ }
236+
207237 /**
208238 * Serialize script arguments (containing web elements and/or shadow roots)
209239 *
0 commit comments