I am working on a website and when I click on a link

I am working on a website and when I click on a link then it opens in a second tab. In order to work on that I need to close the second one. How do I do that?

Hi Rhian,

You can create an Array list of the tabs open and then navigate to the tab you want to close and do it.

Here is what I tried and it worked like charm.

ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
    driver.switchTo().window(tabs2.get(0));
    driver.close();
    driver.switchTo().window(tabs2.get(1));