HtmlUnit ScriptException Errors

I am using HtmlUnitDriver, & here is my code.

HtmlUnitDriver driver = new HtmlUnitDriver(true); driver.get("some url here"); 

I get the following exception:

 Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: SyntaxError: missing ; before statement (http://sales.liveperson.net/hcp/html/mTag.js?site=7824460#1(eval)#1) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:545) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:520) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896) at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:162) at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:221) at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:735) at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:866) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538) at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:871) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1162) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:202) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:440) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373) at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:346) ... 8 more 

Please help me deal with this issue.

+1
source share
3 answers

Many questions are asked referring to such problems. ScriptException raised because you have a syntax error in your javascript. Most browsers can interpret JS even with some errors, but HtmlUnit in this sense is a little inflexible.

Your options:

  • The correct JS code
  • Disable JS in WebClient
  • Do not use HtmlUnit. Use a different framework with better JS support, like PhantomJS (note that this is not a Java platform)
+5
source

I had the same error with liveperson mTag.js

The problem is mTag.js.'s condensed answer.

There are several ways:

  • Replace compact mTag.js with a clean one (LivePerson support required)
  • Work with the “Real” Selenium WebDriver (Firefox Driver or Similar)
+3
source
 _webClient.getOptions().setThrowExceptionOnScriptError(false); 

working in this wrong js script.

+3
source

Source: https://habr.com/ru/post/1438326/


All Articles