title: How to switch to another Tab using Selenium WebDriver with Java
body: <p>I am opening google.com and then clicking on "GMail" hyperlink a new tab is opened on the same browser.</p>
  
  <p>Now I want to switch to this new tab where GMail is opened using Selenium WebDriver.</p>
  
  <p>Code snippet is : </p>
  
  <pre><code>  WebDriver wd = new ChromeDriver();
    wd.get("https://www.google.co.in/?gws_rd=ssl");       
    wd.findElement(By.linkText("Gmail")).sendKeys(Keys.CONTROL,Keys.RETURN);
  </code></pre>
  
  <p>Now I want to go to the tab where I have opened GMail link. I have googled through N number of solutions but none of them worked.</p>
  
  <p>For e.g.</p>
  
  <p>Solution 1 :</p>
  
  <pre><code>String Tab1 = wd.getWindowHandle(); 
  ArrayList&lt;String&gt; availableWindows = new ArrayList&lt;String&gt;(wd.getWindowHandles()); 
  if (!availableWindows.isEmpty()) { 
  wd.switchTo().window(availableWindows.get(1)); 
  }
  </code></pre>
  
  <p>Solution 2 :</p>
  
  <pre><code>driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t");
  </code></pre>
  
  <p>Kindly suggest. I am stuck on this.</p>