I'm trying to use Html Unit to run JavaScript on a webpage in order to change page.
I'm importing:
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.ScriptResult;
and the code is something like:
String javaScriptCode = "changePage(1)";
try{
webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
page = webClient.getPage(url);
newPage = page.executeJavaScript(javaScriptCode).getNewPage();
webClient.close();
} catch (Exception e) {
e.printStackTrace();
}
However I get the error:
[Java] The method getNewPage() is undefined for the type ScriptResult [67108964]
Which is crystal clear, however it doesn't tell me which method I'm supposed to use? Most of what I found on internet is based on the getNewPage method or on getPage but there may have been changes in the library...
see: calling a JavaScript function with HTMLUnit
I'm using:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.33</version>
</dependency>