title: Find a WebElement on the new page using Selenium WebDriver with Java
body: <p>I'm trying to automate a functionality where I have to open a new tab and start to work on this page, but my code still looking the WebElements on the last Tab. I try to switch the tabs with the follow code but its not working.</p>
  
  <pre><code>public void DataManager() throws InterruptedException {
      ArrayList&lt;String&gt; tabs2 = new ArrayList&lt;String&gt; (driver.getWindowHandles());
      driver.switchTo().window(tabs2.get(0));
      driver.close();
      driver.switchTo().window(tabs2.get(1));
      WebElement tes = driver.findElement(By.xpath("//*[@id=\"lui-popover-3\"]/div/ng-transclude/ul/li[2]/button[1]/span[2]"));
      tes.click();                                
  }   
  </code></pre>
  
  <p>What's going on, and how can I fix this?</p>