Calling a JavaScript Function Using HTMLUnit

I am trying to call the showPage('3'); function showPage('3'); this page to use the source code of the page after. I tried to do with htmlUnit as follows:

 WebClient webClient = new WebClient(); webClient.waitForBackgroundJavaScriptStartingBefore(10000); HtmlPage page = webClient.getPage("http://www.visittrentino.it/it/cosa_fare/eventi/risultati?minEventDate=09012014&maxEventDate=31012014&tp=searchForm.thismonth&ltp=gennaio"); String javaScriptCode = "showPage('3');"; ScriptResult result = page.executeJavaScript(javaScriptCode); result.getJavaScriptResult(); System.out.println("result: "+ result); 

But it does not work. He prints:

Result: net.sourceforge.htmlunit.corejs.javascript.Undefined@a303147

and other 10,000 warnings. What am I doing wrong? I need to change the page of this site in order to scan the source code. Is there any other way (and maybe simpler) to call a jsp function from Java code and then go to the source code of the page? Thanks for any help, had a good day.

+6
source share
1 answer

You print the ScriptResult object, not the contents of the page, change the SOP code to result.getNewPage ()

+7
source

All Articles