0

Exact error message : Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.rangeCheck(ArrayList.java:653)

code snippet:

ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
driver.switchTo().window(tabs.get(1));
driver.get(Url2);
MWiesner
  • 8,868
  • 11
  • 36
  • 70

1 Answers1

0

You are getting this exception because your are populating your tabs ArrayList with one tab.

If you want to browse your Url2 in the new tab then use the below code snippet:

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
ArrayList tabs = new ArrayList(driver.getWindowHandles()); 
driver.switchTo().window(tabs.get(0));
driver.get(Url2);
optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37