Skip to content

Commit fb74db5

Browse files
mvorisekrobocoder
authored andcommitted
Convert element to object from execute result
1 parent 608e8b2 commit fb74db5

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

lib/WebDriver/Session.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
* @method void forward() Navigates forward in the browser history, if possible.
3535
* @method void back() Navigates backward in the browser history, if possible.
3636
* @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)
3937
* @method string screenshot() Take a screenshot of the current page.
4038
* @method array getCookie() Retrieve all cookies visible to the current page.
4139
* @method array postCookie($jsonCookie) Set a cookie.
@@ -433,4 +431,43 @@ protected function getElementPath($elementId)
433431
{
434432
return sprintf('%s/element/%s', $this->url, $elementId);
435433
}
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+
}
436473
}

0 commit comments

Comments
 (0)