7

I'm trying to call the function showPage('3'); of this page, for use the page source code after. I tried to do with htmlUnit like so:

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's not working. It prints out:

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

and other 10000 warnings. What am I doing wrong? I need to change the page of this site for do some crawling on the source code. Is there another way (and maybe more easier) for calling jsp-function from Java code and then navigate in the source of the page? Thank you for any help, have a nice day.

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

5 Comments

welcome and if the answer work for u then select it as correct answer
Object result = page.executeJavaScript(javaScriptCode).getJavaScriptResult(); page.getPage(); System.out.println("result: "+result+"\n"+page.getPage()); result is a object and dont have .getNewPage() or something so method...
ScriptResult result = page.executeJavaScript(javaScriptCode); then you can print by using result.getNewPage().
sry man, now i understand you! ty for the help have a nice day!
ScriptResult.getNewPage() was removed in a recent version. The change suggests to use page.getWebClient().getCurrentWindow().getEnclosedPage() instead: github.com/HtmlUnit/htmlunit/commit/…

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.