instaclick / php-webdriver

W3C and Selenium 2 webdriver "thin client" for php 5.3+ and namespaces.
Other
436 stars 62 forks source link

Convert element to object from execute result #110

Closed mvorisek closed 2 years ago

mvorisek commented 2 years ago

Session::execute and Session::execute_async methods must convert the web driver element to object the same way as Container::element and Container::elements methods do.

robocoder commented 2 years ago

Thanks for the PR. This looks like a compat-buster on the 1.x branch since php-webdriver has historically been a (largely) thin wrapper around the W3C and legacy WebDriver protocols.

Can you provide an example of the method call that demonstrates (args and return value) why this is needed?

mvorisek commented 2 years ago

W3C and legacy WebDriver protocols

Yes, it is supported offcially, see facebook impl. https://github.com/php-webdriver/php-webdriver/blob/8ffa927b270e932449e8015abf4d38bb0eff24b7/lib/Remote/RemoteWebDriver.php#L666

My question is, can this PR target 1.x? LOC will be low, no BC break.

mvorisek commented 2 years ago

Example usage:

// expecting:
// a) $wdSession with working \WebDriver\Session driver
// b) loaded webpage with at least one <div> element with some ID attribute

$element = $wdSession->element('xpath', '//div'); // returns instance of \WebDriver\Element

$jsResult = $wdSession->execute([
    'script' => 'return (function (elem) { return [elem, elem.id]; })(arguments[0])',
    'args' => [$element],
]);

// will dump array with:
// [0] (new) instance of \WebDriver\Element to demonstrate conversion from php to webdriver and back
// [1] ID of given element extracted by JS
var_dump($jsResult);
robocoder commented 2 years ago

Thanks for fleshing that out.

robocoder commented 2 years ago

Thanks. This has been tagged as 1.4.12. I'll try to port to the master branch later tonight.

robocoder commented 2 years ago

See 8bb204d8

mvorisek commented 2 years ago

Thank you ❤️