title: How to control loading in Selenium WebDriver?
body: <p>When i try to run my scripts and call this method, when i enter URL into address bar, loading starts and loading take much time, 
  but sometime when refresh page page proper loaded on the spot so please help me out.
  How can i handle this issue in automation. </p>
  
  <pre><code>public static MainPage LaunchBrowserAndLogin(String currentScriptName, String LoginUser) throws Throwable {
              try {
                    killprocess();
                    LaunchBrowser();
                    String siteUrl = null;
                    if (excelSiteURL != null) {
                          if (excelSiteURL.equalsIgnoreCase("")) {
                                siteUrl = CONFIG.getProperty("siteName");
                          }else{
                                if (excelSiteURL.contains("SiteName")) {
                                      siteUrl=excelSiteURL;
                                }
                          }
                    } else {
                          siteUrl = CONFIG.getProperty("SiteName");
                    }
                    driver.get("https://QA.YYYY.com/ABC9/#/login"); 
                    System.out.println("URL for Login: "+siteUrl);
                    CheckErrorPageNotFound();
                    driver.manage().timeouts().pageLoadTimeout(Long.parseLong(CONFIG.getProperty("pageLoadTime")), TimeUnit.SECONDS);
                    enterUserID(currentScriptName, LoginUser);
                    enterPasswd(currentScriptName);
                    MandatoryFieldSkipErrMsg("~~~~~~ Mandatory Field is skipped, Getting Error: ");
                    ClickLoginButton();
                    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
              }catch(){
                  DesireScreenshot("AfterClickOnLoginButton");
                  String stackTrace = Throwables.getStackTraceAsString(t);
                  String errorMsg = t.getMessage();
                  errorMsg = "\n\n\n\n Login failed.See screenshot 'LoginFailed' \n\n\n\n" + errorMsg + stackTrace;
                  Exception c = new Exception(errorMsg);
                  ErrorUtil.addVerificationFailure(c);
                  killprocess();
                  IsBrowserPresentAlready = false;
                  throw new Exception(errorMsg);
              }
           return new MainPage(driver);
  }
  </code></pre>