我有这段代码:
driver = new HtmlUnitDriver();
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
baseUrl = "http://www.url.com/";
driver.get(baseUrl + "/");
...
但是,如果我尝试运行我有这个例外:
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method "match" of undefined (http://www.url.com//javascript/jquery.ceebox/jquery.swfobject.js#2)
我怎么解决?还有办法吗?
答案 0 :(得分:0)
javascript支持不符合标准,如果您不想抑制这些错误,可以使用:
webClient.getOptions().setThrowExceptionOnScriptError(false);
在我的几乎所有项目中,我的通用webclient配置如下所示:
WebClient client = new WebClient(BrowserVersion.FIREFOX_17);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setCssEnabled(false);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setPrintContentOnFailingStatusCode(false);