0

I am completely new to HtmlUnit and I do not really know how to read and understand the page source of a website. Nonetheless, I have written code (learned from this tutorial) to try and access the following website

Then I am stuck, as I am not familiar with javascript. This is what I want to achieve:

  • I would like to type 328 in the textfield on the left menu on that website

  • and click submit button

So that I can be brought to the next page.

UPDATE: I managed to resolve page access problem by adding a line to my code. But I am still having trouble to locate the input text field, type in some input and click the button, so that i can be landed to the next page.

public void testing() throws Exception {
           /* turn off annoying htmlunit warnings */
    java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);
    try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
        final HtmlPage page = webClient.getPage("http://www.aastocks.com/en/stock/DetailQuote.aspx?&symbol=1");
        final HtmlDivision div = page.getHtmlElementById("LeftMenu_Button");
    }
}
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
mynameisJEFF
  • 4,073
  • 9
  • 50
  • 96

1 Answers1

0

The website has a CSS with URL //:, which wasn't correctly handled by HtmlUnit, and it is now fixed in SVN.

Please get the latest build, with which the below code works:

    try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {

        final HtmlPage page = webClient.getPage("http://www.aastocks.com/en/stock/DetailQuote.aspx?&symbol1");
        HtmlInput input = page.getHtmlElementById("PY_txt");
        input.type("328");

        final HtmlPage page2 = page.getHtmlElementById("imgHKStockSubmit").click();
        System.out.println(page2.getUrl());
        System.out.println(page2.asText());
    }
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56