britka / playwrightium

Run Selenium or Selenide tests with Playwright Java
Apache License 2.0
55 stars 4 forks source link

`drvier.executeScript()` doesn't properly cast script result when script args are omitted. #102

Open BorisOsipov opened 1 week ago

BorisOsipov commented 1 week ago
    @Test
    public void jsExecuteCanCastToWebElement() {
       WebElement element = executeJavaScript("return document.activeElement");
    }

    static  <T> T executeJavaScript(String jsCode, Object... arguments) {
        return (T) jsExecutor(driver).executeScript(jsCode, arguments); 
    }

It fails with java.lang.ClassCastException: class java.lang.String cannot be cast to class org.openqa.selenium.WebElement

WebElement element = executeJavaScript("return document.activeElement", "foobar"); works fine. At least doesn't throw cast error.