Its a good question if we dont know the name of window so how can we switch to another window, For this we can use this code
//Store the current window handle
String winHandleBefore = driver.getWindowHandle();
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
//Perform the actions on new window
//Close the new window, if that window no more required
//driver.close();
//Switch back to original browser (first window)
//driver.switchTo().window(winHandleBefore);
in this code threw window handler we are all avalable window then we are performing some action on that new window and coming back to orignal window ,i hope you got the point.