TestProject Forum
Powered by leading experts in the test automation community

Close window tab in selenium driver

I need to switch between tabs in chrome but first I would like to close the previous tab.

Is there a method for this ?

In order to do so you would need to get the windows handles

    String currentWindowHandle = driver.getWindowHandle();
    
    // click link to open new tab

    driver.switchTo().window(currentWindowHandle);
    driver.close();

That should close the previous tab and return you to the new one.