I am trying to simulate a search site travel ticket with HtmlUnit. The goal is to have the page Result of the search. My code returns the search page(waiting for the result ...)
Here is the code:
public class TestHtmlUnit {
public static void main(String[] args) throws Exception {
// Create and initialize WebClient object
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
webClient.setThrowExceptionOnScriptError(false);
webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws IOException {
System.out.println("handleRefresh");
}
});
// visit Yahoo Mail login page and get the Form object
HtmlPage page = (HtmlPage) webClient.getPage("http://www.voyages-sncf.com/");
HtmlForm form = page.getFormByName("TrainTypeForm");
// Enter login and passwd of
form.getInputByName("origin_city").setValueAttribute("paris");
form.getInputByName("destination_city").setValueAttribute("marseille");
form.getInputByName("outward_date").setValueAttribute("28/03/2013");
// Click "Sign In" button/link
page = (HtmlPage) form.getInputByValue("Rechercher").click();
// Print the newMessageCount to screen
//System.out.println("newMessageCount = " + newMessageCount);
// System.out.println(page.asHTML());
System.out.println(page.asText());
}
}