public void waitForPageToLoad() {
wait(1);
JavascriptExecutor js=(JavascriptExecutor)driver;
String state = (String)js.executeScript("return document.readyState");
while(!state.equals("complete")){
wait(2);
state = (String)js.executeScript("return document.readyState");
}
}
The above code will wait till the page is fully loaded and continues further.
The below code waits only for 5 seconds, it cannot be guaranteed that the page can be loaded in 5 seconds or any other value.
driver.manage().timeouts().pageLoadTimeout(05, TimeUnit.SECONDS);