Java Redirect HtmlUnit Problems

I work in an online bank. I would like to log in to get a balance. I did some research and I found the helpful HtmlUnit code from other posts. However, I am stuck with page redirection processing. The path is as follows: The main login form (page 1) gives a new page that verifies the credentials (page 2). Up to this point, everything is fine with me, but I can’t find a solution to extract the home page (page 3), here is the code:

import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class WellsF { public static void main(String[] args) throws Exception { WebClient webClient = new WebClient(BrowserVersion.CHROME_16); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setCssEnabled(true); webClient.getOptions().setUseInsecureSSL(true); webClient.getOptions().setRedirectEnabled(true); HtmlPage page1 = webClient .getPage("https://www.wellsfargo.com/home.jhtml"); final HtmlForm form = (HtmlForm) page1.getElementById("frmSignon"); form.getInputByName("userid").setValueAttribute("user id"); form.getInputByName("password").setValueAttribute("user password"); HtmlPage page2 = (HtmlPage) form.getInputByName("btnSignon").click(); synchronized (page2) { page2.wait(5000); System.out.println(page2.asText()); System.out.println("=========================== page2\n"); } HtmlPage page3 = (HtmlPage) webClient.openWindow(page2.getUrl(), "signon").getEnclosedPage(); System.out.println(page3.asText()); webClient.closeAllWindows(); } } 
+6
source share
1 answer

please try with the code below and check if it works:

  HtmlPage page3 = (HtmlPage) webClient.getPage(page2.getUrl()); webClient.getOptions().setTimeout(10*1000); 
0
source

All Articles