Switch tabs using Selenium WebDriver with Java

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

This code perfectly worked for me. Try it out. You always need to switch your driver to new tab, before you want to do something on new tab.

Leave a Comment