title: How to handle the new window in Selenium WebDriver using Java?
body: <p>This is my code:</p>
  
  <pre><code>driver.findElement(By.id("ImageButton5")).click();
  //Thread.sleep(3000);
  String winHandleBefore = driver.getWindowHandle();
  driver.switchTo().window(winHandleBefore);
  driver.findElement(By.id("txtEnterCptCode")).sendKeys("99219");
  </code></pre>
  
  <p>Now I have the next error:</p>
  
  <blockquote>
    <p>Exception in thread "main" org.openqa.selenium.NoSuchElementException:
    Unable to find element with id == txtEnterCptCode (WARNING: The server
    did not provide any stacktrace information)
        Command duration or timeout: 404 milliseconds.</p>
  </blockquote>
  
  <p>Any ideas?</p>