title: Switch to parent window after child window is closed by driver.close() throws Exception
body: <p>I have a scenario where I perform the following steps:</p>
  
  <ol>
  <li>Open browser --> navigate to and click on link which opens a new window</li>
  <li>Switch to child window using <code>driver.switchTo().window(handle)</code> --> perform operations on the child window.</li>
  <li>Close the child window.</li>
  <li>Switch back to the parent window.</li>
  <li>Get the title of the current window.</li>
  </ol>
  
  <p>Steps 1 to 3 works just fine. But step 4 throws an exception. And for better clarity I have included the log messages before the exception is throw.n</p>
  
  <pre><code>// Switching to child window
  [testng] 23:40:33.794 INFO - Executing: [switch to window: 3efe9598-2a08-40ec-a950-d4a6e2182b20])
  [testng] W 2016-02-08 23:40:33:808 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
  [testng] W 2016-02-08 23:40:33:821 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
  [testng] 23:40:33.942 INFO - Done: [switch to window: 3efe9598-2a08-40ec-a950-d4a6e2182b20]
  [testng] 23:40:33.944 INFO - Executing: [get title])
  [testng] 23:40:33.955 INFO - Done: [get title]
  [testng] 23:41:34.708 INFO - Executing: [close window])
  [testng] 23:41:34.719 INFO - Done: [close window]
  // Switch to parent window
  [testng] 23:41:34.751 INFO - Executing: [switch to window: b2dd5b6e-c891-498f-871b-1fc80b4afef2])
  [testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
  [testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(504) Unable to find current browser
  [testng] W 2016-02-08 23:41:34:765 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
  [testng] W 2016-02-08 23:41:34:865 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
  [testng] W 2016-02-08 23:42:34:875 response.cc(69) Error response has status code 21 and message 'Timed out waiting for page to load.' message
  [testng] 23:42:34.879 WARN - Exception thrown
  [testng] org.openqa.selenium.TimeoutException: Timed out waiting for page to load. (WARNING: The server did not provide any stacktrace information)
  [testng] Command duration or timeout: 60.13 seconds
  [testng] Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
  [testng] System info: host: 'x-x-x-x', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
  [testng] Driver info: org.openqa.selenium.ie.InternetExplorerDriver
  [testng] Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:42778/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=true, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=accept}]`
  </code></pre>
  
  <p>We are using a special framework based on flashSelenium and our developers here have managed to integrate flash Selenium with WebDriver (Originally flash Selenium was intended to work with RC). From my understanding, our framework involves flashSelenium, RC and Webdriver components. I am new to the team and the framework API is not in active development (no support). </p>
  
  <p>When I put a try catch around step 4, step 5 is executed correctly. I can see that the exception block around step 4 printing the error!!</p>
  
  <p><strong>So here goes my question:
  Does driver.switchTo().window(parentWindow) give an exception as shown above in any circumstance?</strong></p>
  
  <p>As from the below log segment I can see that the switch to window executes but the internal method of switch window throws an Exception as the consecutive lines suggest.</p>
  
  <pre><code>[testng] 23:41:34.751 INFO - Executing: [switch to window: b2dd5b6e-c891-498f-871b-1fc80b4afef2])
  [testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
  [testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(504) Unable to find current browser
  [testng] W 2016-02-08 23:41:34:765 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
  [testng] W 2016-02-08 23:41:34:865 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
  [testng] W 2016-02-08 23:42:34:875 response.cc(69) Error response has status code 21 and message 'Timed out waiting for page to load.' message
  [testng] 23:42:34.879 WARN - Exception thrown
  </code></pre>
  
  <p>Code looks like below</p>
  
  <pre><code>String parentHandle = driver.getWindowHandle();
  // Click on the element code goes here (This is in flash selenium)
  Set&lt;String&gt; windowhandles = driver.getWindowHandles(); 
  for (String windowHandle : windowHandles) {
      driver.switchTo().window(windowHandle);
  }
  
  System.out.println("Child title : " + driver.getTitle());
  driver.close;
  // Exception is thrown in the below line. If a try catch is placed
  // the last line gets executed (sysout). But I can see the catch getting executed.
  driver.switchTo().window(parentHandle);
  System.out.println("Child title : " + driver.getTitle());
  </code></pre>