switchTo() command is used to switch between windows, frames or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”.
Get the window handle of the window you wish to switch to
String handle= driver.getWindowHandle();
Switch to the desired window
driver.switchTo().window(handle);
Alternatively
for(String handle= driver.getWindowHandles())
{ driver.switchTo().window(handle); }