HtmlUnit ScriptException错误 [英] HtmlUnit ScriptException errors

查看:359
本文介绍了HtmlUnit ScriptException错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HtmlUnitDriver,&这是我的代码.

I am using HtmlUnitDriver,& here is my code.

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

我正在跟踪异常:

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

请帮助我解决此问题.

推荐答案

问了很多有关此类问题的问题.出现ScriptException的原因是您的javascript中存在语法错误.大多数浏览器即使在出现某种错误的情况下也可以解释JS,但是HtmlUnit在这种意义上有点不灵活.

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.

您的选择是:

  1. 正确的JS代码
  2. WebClient
  3. 中禁用JS
  4. 不要使用HtmlUnit.使用具有更好JS支持的其他框架,例如 PhantomJS (请注意,它不是基于Java的框架)
  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)

这篇关于HtmlUnit ScriptException错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆