5

I am using HtmlUnitDriver,& here is my code.

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

I am getting 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 to sort out this issue.

4
  • 1
    Put little more code , and what actually you are putting as URL. Commented Oct 4, 2012 at 6:17
  • It's most likely the string isn't formatted correctly. It sounds like it wants a specific format and not just a URL. Commented Oct 4, 2012 at 6:17
  • 1
    Well it looks like that's complaining about the Javascript, not the Java code... what does your Javascript look like? Commented Oct 4, 2012 at 6:17
  • Can you post some more code, as exception says you have missed a semi-colon somewhere... We want to see that "Somewhere".. Commented Oct 4, 2012 at 6:17

3 Answers 3

7

Many questions are asked referencing this kind of issues. The ScriptException is raised because you have a syntactical error in your javascript. Most browsers manage to interpret the JS even with some kind of errors but HtmlUnit is a bit inflexible in that sense.

Your options are:

  1. Correct JS code
  2. Disable JS in the WebClient
  3. Don't use HtmlUnit. Use a different framework with better JS support such as PhantomJS (note it is not a Java-based framework)
Sign up to request clarification or add additional context in comments.

Comments

6
_webClient.getOptions().setThrowExceptionOnScriptError(false);

works in this incorrect JS scenario.

Comments

4

I had the same error with the liveperson mTag.js

The problem is with the compacted mTag.js response.

There are several workaround:

  1. Replace the compacted mTag.js with a clear one (requires LivePerson support)
  2. Work with a 'real' Selenium WebDriver (Firefox Driver or similar)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.