|
34 | 34 | * @method void forward() Navigates forward in the browser history, if possible.
|
35 | 35 | * @method void back() Navigates backward in the browser history, if possible.
|
36 | 36 | * @method void refresh() Refresh the current page.
|
37 |
| - * @method mixed execute($jsonScript) Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. (synchronous) |
38 |
| - * @method mixed execute_async($jsonScript) Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. (asynchronous) |
39 | 37 | * @method string screenshot() Take a screenshot of the current page.
|
40 | 38 | * @method array getCookie() Retrieve all cookies visible to the current page.
|
41 | 39 | * @method array postCookie($jsonCookie) Set a cookie.
|
@@ -433,4 +431,43 @@ protected function getElementPath($elementId)
|
433 | 431 | {
|
434 | 432 | return sprintf('%s/element/%s', $this->url, $elementId);
|
435 | 433 | }
|
| 434 | + |
| 435 | + /** |
| 436 | + * @param mixed $data |
| 437 | + * |
| 438 | + * @return mixed |
| 439 | + */ |
| 440 | + private function webDriverElementMulti($data) |
| 441 | + { |
| 442 | + $element = $this->webDriverElement($data); |
| 443 | + if ($element !== null) { |
| 444 | + return $element; |
| 445 | + } elseif (is_array($data)) { |
| 446 | + foreach ($data as $k => $v) { |
| 447 | + $data[$k] = $this->webDriverElementMulti($v); |
| 448 | + } |
| 449 | + } |
| 450 | + |
| 451 | + return $data; |
| 452 | + } |
| 453 | + |
| 454 | + /** |
| 455 | + * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. (synchronous) |
| 456 | + */ |
| 457 | + public function execute($jsonScript) |
| 458 | + { |
| 459 | + $result = parent::execute($jsonScript); |
| 460 | + |
| 461 | + return $this->webDriverElementMulti($result); |
| 462 | + } |
| 463 | + |
| 464 | + /** |
| 465 | + * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. (asynchronous) |
| 466 | + */ |
| 467 | + public function execute_async($jsonScript) |
| 468 | + { |
| 469 | + $result = parent::execute_async($jsonScript); |
| 470 | + |
| 471 | + return $this->webDriverElementMulti($result); |
| 472 | + } |
436 | 473 | }
|
0 commit comments