How to switch between multiple windows in Selenium?

How to switch between multiple windows in Selenium?

Hi Mark,

Selenium has driver.getWindowHandles() and driver.switchTo().window(“{windowHandleName}”) commands to work with multiple windows.

The getWindowHandles() command returns a list of ids corresponding to each window. If we pass a particular window handle to the driver.switchTo().window(“{windowHandleName}”) command then we can switch control/focus to that particular window.

for (String windowHandle : driver.getWindowHandles()) { driver.switchTo().window(handle); }