giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
601 stars 270 forks source link

Execute JS script with element as parameter #428

Closed chandon closed 4 years ago

chandon commented 5 years ago

Hello,

With Java, i can call a JS script with an Element as parameter. Example (with Firefox or Chrome) :

WebElement element=driver.findElement(By.cssSelector("#myElement"));
((JavascriptExecutor) driver).executeScript("elem=arguments[0];console.log(elem);", element);

=> in the browser context, "elem" contains the node corresponding to "element" in java

With phpunit-selenium, I tried :

$element=$this->byCssSelector("#myElement");
$this->execute(
        array(
        'script'=>"elem=arguments[0];console.log(elem);",
        'args'=>array($element),
        )
    );

=> in the browser context, "elem" contains an empty Object...

How to do that with phpunit-selenium ? Thanks

pajon commented 4 years ago

Hi @chandon

This package doesn't have this feature. You can still JS selector

$this->execute([
        'script'=>"elem = document.getElementById('myElement');console.log(elem);",
        'args'=>[],
]);