Вы можете попробовать этот ниже код
//define your main window
String mainWindowHandler = driver.getWindowHandle();
//handle your popup
Set<String> popup = driver.getWindowHandles();
for (String winHandle : popup) {
if(!winHandle.equals(mainWindowHandler)) {
//switch to popup
driver.switchTo().window(winHandle);
System.out.println(driver.getTitle());
//close popup, or your action
driver.close();
//back to main window
driver.switchTo().window(mainWindowHandler);
}
}