title: Selenium throws IndexOutOfBoundsException while opening new tab
body: <p>Selenium Java program throws  <strong>IndexOutOfBoundsException</strong> exception when  executed below code to open new tab in Chrome. </p>
  
  <p>Java Code:</p>
  
  <pre><code>System.setProperty("webdriver.chrome.driver", "/Users/john/Desktop/chromedriver");
                      WebDriver driver = new ChromeDriver();
                      driver.manage().window().maximize();
                      String baseUrl = "http://google";
                      driver.get(baseUrl);
                      driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
  
                      ArrayList&lt;String&gt; tabs = new ArrayList&lt;String&gt;(driver.getWindowHandles()); 
                      driver.switchTo().window(tabs.get(1)); // switches to  new tab
                      driver.get("https://www.facebook.com");
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 48571
  Only local connections are allowed.
  May 12, 2017 12:54:14 AM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
      at java.util.ArrayList.rangeCheck(ArrayList.java:653)
      at java.util.ArrayList.get(ArrayList.java:429)
      at test.SeleniumTest.main(SeleniumTest.java:31)
  </code></pre>