Fechando todas as guias abertas, exceto a primeira guia / guia principal usando o webdriver
Alguém pode me dizer como fechar todas as guias abertas, exceto a primeira guia / guia principal usando o webdriver?
Eu tentei abaixo, mas está fechando todas as abas incluindo a primeira aba também.
public static void closeTabs() {
String wh1=driver.getWindowHandle();
String cwh=null;
while(wh1!=cwh)
{
new Actions(driver).sendKeys(Keys.CONTROL).sendKeys(Keys.NUMPAD1).perform();
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL, Keys.TAB);
cwh=driver.getWindowHandle();
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL+"w");
}
}
Por favor me ajude.