title: wait for child window in selenium webdriver using java
body: <p>How to wait for the child window in selenium web driver</p>
  
  <p>when I click on the submit button it leads me to child window and I assert the Url but sometimes the child window takes time to come
  Currently using thread.sleep(4000)
  <strong>But this is the wrong way.</strong></p>
  
  <pre><code>    // parent window
      String subWindowHandler = null;
  
      Set&lt;String&gt; handles = driver.getWindowHandles(); // get all window
      // handles
      Iterator&lt;String&gt; iterator = handles.iterator();
      while (iterator.hasNext()) {
          subWindowHandler = iterator.next();
      }
      driver.switchTo().window(subWindowHandler); // switch to popup window
      System.out.println(driver.getTitle());
  
      String Current_Url = driver.getCurrentUrl();
  
      System.out.println("Current open Url in other Tab --&gt;" + Current_Url);
  
      try {
          Assert.assertEquals("http://intelliview-dev.psi.psigroupinc.com/Reports/ReportView.aspx", Current_Url);
          logger.info("Assertion Passed");
          logger.info("User is able to login to My Account Application");
      } catch (AssertionError e) {
          logger.info("Assertion Failed");
          logger.info("User Provide Invalid Username or Password");
          throw e;
  
      }
  </code></pre>