From: Ahmed A. <asa...@ya...> - 2015-11-10 18:27:16
|
Hi, new WebClient(); uses IE8 by default. Please change that to new WebClient(BrowserVersion.CHROME); Ahmed From: blackman <ma...@ho...> To: htm...@li... Sent: Tuesday, November 10, 2015 6:32 PM Subject: [Htmlunit-user] HtmlUnit and angularJS Hello all, I'm using the latest stable release of Htmlunit. I wrote the following snipet of code to fecth the page https://exchange.xforce.ibmcloud.com/index.html: When viewed in Firefox or IE, the source of this page contains this non-empty div: * <div id="wrapper" class="" autoscroll="true" ui-view="" ng-if="!loading" style=""> <div id="homepage-wrapper"> ....other divs </div> </div> * The code : * try { WebClient webClient = new WebClient(); webClient.getOptions().setCssEnabled(true); webClient.setCssErrorHandler(new SilentCssErrorHandler()); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setTimeout(5000); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setPopupBlockerEnabled(true); webClient.getOptions().setPrintContentOnFailingStatusCode(false); webClient.waitForBackgroundJavaScript(10000); HtmlPage page = webClient.getPage("https://exchange.xforce.ibmcloud.comindex.html"); System.out.println(page.asXml()); } catch (Throwable err) { err.printStackTrace(); } * When i run this code , i've lots of scripts errors : * com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (https://exchange.xforce.ibmcloud.com/scripts/vendor.js#31) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:865) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:747) at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1032) at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:395) at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:270) at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:290) ... caused by Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "angular" is not defined. (https://exchange.xforce.ibmcloud.com/scripts/external/ng-ckeditor.js#3) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3935) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3919) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3996) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.name(ScriptRuntime.java:1846) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1627) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411) at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitCont * and the page.asXml() give me an empty div * <div ng-if="!loading" id="wrapper" ui-view="" autoscroll="true"> </div> * >From the error , I suppose htmunit not able to run AngularJS scripts on this page. Or is the problem with the page itself ? Why the div is empty? and is there any way of getting its contents even if there is script errors? Many thanks. -- View this message in context: http://htmlunit.10904.n7.nabble.com/HtmlUnit-and-angularJS-tp37720.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |