@@ -62,6 +62,16 @@ protected function obsoleteMethods()
62
62
return [];
63
63
}
64
64
65
+ /**
66
+ * Return array of chainable method/property names
67
+ *
68
+ * @return array
69
+ */
70
+ protected function chainable ()
71
+ {
72
+ return [];
73
+ }
74
+
65
75
/**
66
76
* Constructor
67
77
*
@@ -172,6 +182,10 @@ public function __call($name, $arguments)
172
182
return new $ className ($ this ->url . '/ ' . $ this ->extensions [$ name ][1 ]);
173
183
}
174
184
185
+ if (count ($ arguments ) === 0 && array_key_exists ($ name , $ this ->chainable ())) {
186
+ return call_user_func ([$ this , $ name ]);
187
+ }
188
+
175
189
if (preg_match ('/^(get|post|delete)/ ' , $ name , $ matches )) {
176
190
$ requestMethod = strtoupper ($ matches [0 ]);
177
191
$ webdriverCommand = strtolower (substr ($ name , strlen ($ requestMethod )));
@@ -204,6 +218,22 @@ public function __call($name, $arguments)
204
218
return $ result ['value ' ];
205
219
}
206
220
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
+
207
237
/**
208
238
* Serialize script arguments (containing web elements and/or shadow roots)
209
239
*
0 commit comments