title: Switch to pop up window using Selenium
body: <p>I am trying to switch to a popup window but I am having trouble doing so. The link that I click on is to redirect me to an email popup window.</p>
  
  <p>My code is:</p>
  
  <pre><code>public String determineIfCorrectUrlOnPopUp() {
  
      clickOnEmailThisSeller();
      for (String currentWindow: driver.getWindowHandles()) {
  
          driver.switchTo().window(currentWindow);
      }
  
      System.out.println(driver.getCurrentUrl());
      return driver.getCurrentUrl();
  
  }
  </code></pre>
  
  <p>but it prints out the parent window URL instead of the popup window. I am not sure what I am doing wrong?</p>