title: Selenium switchTo return error org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
body: <p>I have scenario to click hyperlink, and will open new tab (active window will move to new tab after click hyperlink)</p>
  
  <p>When i try to move to webdriver to new tab using <code>switchTo()</code> method, then followed by <code>WebDriverWait.until</code> browser automatically close with error</p>
  
  <pre><code>org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
  from no such execution context
    (Session info: chrome=73.0.3683.103)
  </code></pre>
  
  <p>I use <code>System.out.println(driver.getWindowHandle())</code> and i can see driver moving to new tab.</p>
  
  <p>How i can fix above error?
  I have try using Iterator for loop into windowHandle</p>
  
  <p>Seems can't use WebDriverWait.until(ExpectedConditions) to wait for new tab.
  Always getting an error <code>cannot determine loading status from no such execution context</code></p>
  
  <p>Weird thing, I can use <code>Thread.sleep(1000)</code>.</p>
  
  <p>How i can avoid using Thread.sleep in this case?
  Because implicit wait can't work too</p>
  
  <p><strong>Working code with Thread.sleep()</strong></p>
  
  <pre><code>public class MyCode {
      private WebDriver driver;
      private WebDriverWait wait;
  
      @Test
      public void openPrestaShopFromDemoWebsite() {
          System.setProperty("webdriver.chrome.driver", "chromedriver");
          ChromeOptions chromeOptions = new ChromeOptions()
                  .addArguments("--start-maximized", "--incognito");
  
          driver = new ChromeDriver(chromeOptions);
          driver.navigate().to("http://demo.prestashop.com");
          wait = new WebDriverWait(driver, 10);
          wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loadingMessage")));
  
          driver.switchTo().frame("framelive");
          String parentTab = driver.getWindowHandle();
          driver.findElement(By.partialLinkText("Ecommerce software by PrestaShop")).click();
  
          Set&lt;String&gt; windowHandles = driver.getWindowHandles();
          Iterator&lt;String&gt; it = windowHandles.iterator();
  
          while (it.hasNext()) {
              String newTab = it.next();
  
              if (!parentTab.equals(newTab)) {
                  driver.switchTo().window(newTab);
  
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
  
                  wait.until(ExpectedConditions.titleIs("Create and develop your business with PrestaShop"));
                  driver.close();
              }
          }
  
          driver.switchTo().window(parentTab);
          driver.switchTo().frame("framelive");
          assertThat(driver.findElement(By.linkText("Personal info")).isDisplayed());
  
          driver.quit();
  
      }
  }
  </code></pre>
  
  <p><strong>Not working code (cannot determine loading status from no such execution context)</strong></p>
  
  <pre><code>public class MyCode {
      private WebDriver driver;
      private WebDriverWait wait;
      private WebElement element;
  
      @Test
      public void openPrestaShopFromDemoWebsite() {
          System.setProperty("webdriver.chrome.driver", "chromedriver");
          ChromeOptions chromeOptions = new ChromeOptions()
                  .addArguments("--start-maximized", "--incognito");
  
          driver = new ChromeDriver(chromeOptions);
          driver.navigate().to("http://demo.prestashop.com");
          wait = new WebDriverWait(driver, 10);
          wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loadingMessage")));
  
          driver.switchTo().frame("framelive");
          String parentTab = driver.getWindowHandle();
          driver.findElement(By.partialLinkText("Ecommerce software by PrestaShop")).click();
  
          Set&lt;String&gt; windowHandles = driver.getWindowHandles();
          Iterator&lt;String&gt; it = windowHandles.iterator();
  
          while (it.hasNext()) {
              String newTab = it.next();
  
              if (!parentTab.equals(newTab)) {
                  driver.switchTo().window(newTab);
  
                  wait.until(ExpectedConditions.titleIs("Create and develop your business with PrestaShop"));
                  driver.close();
              }
          }
  
          driver.switchTo().window(parentTab);
          driver.switchTo().frame("framelive");
          assertThat(driver.findElement(By.linkText("Personal info")).isDisplayed());
  
          driver.quit();
  
      }
  }
  </code></pre>