undetected Selenium
undetected Selenium

Reputation: 193308

org.openqa.selenium.JavascriptException: SyntaxError: '' string literal contains an unescaped line break while using executeScript through Selenium

org.openqa.selenium.JavascriptException: SyntaxError: '' string literal contains an unescaped line break while using executeScript through Selenium

executeScript() is working perfect with single line String as an example:

String myText = "80120804076";

But when I am trying to send a multiline String JavascriptException is raised.

I have been through the related discussions:

Reference: SyntaxError: unterminated string literal

Still no clue where I am going wrong. Can anyone help me out ?

Upvotes: 1

Views: 6903

Answers (2)

Vladimir Efimov
Vladimir Efimov

Reputation: 799

Here is what worked for me:

1) added an extra slash before every \n to make it \\n

2) added extra slash before apostrphne hasn\'t to make it hasn\\'t

"No, there is no way to hide the console window of the chromedriver.exe \\n"
                + "in the .NET bindings without modifying the bindings source code. This is seen \\n"
                + "as a feature of the bindings, as it makes it very easy to see when your code \\n"
                + "hasn\\'t correctly cleaned up the resources of the ChromeDriver, since the console window \\n"
                + "remains open. In the case of some other languages, if your code does not properly clean up \\n"
                + "the instance of ChromeDriver by calling the quit() method on the WebDriver object, \\n"
                + "you can end up with a zombie chromedriver.exe process running on your machine.";

Upvotes: 3

Bill Hileman
Bill Hileman

Reputation: 2836

Have you tried this method:

String myText = {"No, there is no way to hide the console window of the chromedriver.exe",
                 "in the .NET bindings without modifying the bindings source code. This is seen",
                 "as a feature of the bindings, as it makes it very easy to see when your code",
                 "hasn\'t correctly cleaned up the resources of the ChromeDriver, since the console window",
                 "remains open. In the case of some other languages, if your code does not properly clean up",
                 "the instance of ChromeDriver by calling the quit() method on the WebDriver object,",
                 "you can end up with a zombie chromedriver.exe process running on your machine."}.join("\n");

Upvotes: 0

Related Questions