I'm working in an online banking application. I would like to login to retrieve the balance. I've been doing some research, and I found some useful HtmlUnit code from other posts. However, I'm stuck handling page's redirect. The path is as follows : Main login form (page1), yields a new page that verify credentials (page2). Up to this point I'm doing fine, but I can't find the solution to retrieve home page (page3), 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();
}
}
webClient.getCurrentWindow().getEnclosedPage()
to see if that is ok. I assume that you are having problems with redirects over anything else. – Tobytobye