0

How do I wait till the response is loaded and then get the page?

        url = new URL("http://somesite.com/sompage.jsp?somefield=something");           

        URLConnection conn = url.openConnection();

        BufferedReader br = new BufferedReader(
                           new InputStreamReader(conn.getInputStream()));

        String inputLine;

        while ((inputLine = br.readLine()) != null) {
            System.out.println(inputLine);
        }


        br.close();
  • The webpage has to get some values from a webservice. So what I see in html is "Async response not received yet." – user3055952 Feb 15 '16 at 18:20

2 Answers2

0

I suggest you use a third-party library called Selenium. This is basically a headless browser that can wait until the element you are looking for loads completely. A simple example taken from other SO post would be:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutValue);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));
Community
  • 1
  • 1
Joel Min
  • 3,387
  • 3
  • 19
  • 38
0
url = new URL("http://somesite.com/sompage.jsp?somefield=something");
URLConnection conn = url.openConnection();
try {
    Thread.sleep(2000); // 1000 milliseconds is one second. Wait for IM Ticket Generation
} catch (InterruptedException ex) {
    Thread.currentThread().interrupt();
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = br.readLine()) != null) {
    System.out.println(inputLine);
}
br.close();

Adding sleep before using the resource worked.

Tunaki
  • 132,869
  • 46
  • 340
  • 423