Let's understand what a window handle is. A window handle is an alphanumeric ID that gets assigned to each window when the object of WebDriver is instantiated. Selenium uses this ID to identify each window and switch between them.
Window handles
Fetching the window handles
In order to switch between all available windows, Selenium first needs to get hold of the window handles. For this purpose, there are two methods provided: getWindowHandle() and getWindowHandles():
- getWindowHandle(): This method, when invoked on the WebDriver object, returns the handle of the current window which has the focus
- getWindowHandles(): This method, when invoked on the WebDriver object, returns a set of all open windows