title: Switching control to a Modal window (not an alert) using Selenium Webdriver
body: <p>I have a web application that launches the Save Window (which is Modal) when I click on the Save Button. This window takes uptil 10 seconds to load completely (I can counter this with a wait).
  I need to carry out some actions in this window, before I complete the save. </p>
  
  <p>The problem I face is
  - The moment the modal window is launched, there is no way I can use a driver.SwitchTo() or driver.Manage().GetAllWindowHandles() etc. I confirmed this with the following lines of Code.</p>
  
  <pre><code>driver.findElement(By.xpath("//*[@id='toolbar']/a[1]")).click();
  // After the above line is executed, the Popup gets launched
  
  Set&lt;String&gt; sWindowHandles = driver.getWindowHandles();
  System.out.println("Popup"); 
  System.out.println(driver.getWindowHandles().size()); // This always prints "1"
  </code></pre>
  
  <p>The 3 lines above are not executed at all (or at least not for a long time) until I explicitly close the Popup Window.</p>
  
  <p>How do I work on some control that exists within the Save Window (Modal), when there is no way I can find the Window's handler? </p>
  
  <pre><code>for(String winHandle : driver.getWindowHandles()){
      driver.switchTo().window(winHandle);
  }
  </code></pre>
  
  <p>doesn't work, because immediately after the modal window is opened (makes sense to GetWindowHandles only after it is launched), the subsequent lines aren't executed at all.
  I'm caught in a deadlock. Please help me out.</p>