Skip to content Skip to sidebar Skip to footer

Passing A String Value To Javascript Executor In Selenium

I know this question is already asked.I searched for multiple answers and not found my problem. if (driver instanceof JavascriptExecutor) { System.out.println('In try');

Solution 1:

Try this:

    if (driver instanceof JavascriptExecutor) {
            System.out.println("In try");
            ((JavascriptExecutor)driver).executeScript("document.getElementById('comment').value=\'" + line1 + line2 + "\';");
    } else {
            throw new IllegalStateException("This driver does not support JavaScript!");
    }

To pass a string element to your script String, You need to put \ before the single quotes. Hope this helps.


Post a Comment for "Passing A String Value To Javascript Executor In Selenium"