Get Window Handles

The Get Window Handles command of the WebDriver API returns a list of all WebWindows. Each tab or window, depending on whether you are using a tabbed browser, is associated by a window handle that is used as a reference when switching to the window.

In order to determine whether or not a particular interaction with the browser opens a new window, one can obtain the set of window handles before the interaction is performed and compare it with the set after the action is performed.

Syntax

Method URI template
GET /session/{session id}/window/handles

URL parameters

session id
Identifier of the session.

Errors

Invalid session ID
Session does not exist.

Example

C#:

using System.Collections.ObjectModel;
using OpenQA.Selenium.Firefox;

namespace MDNWebDriverExamples
{
    class Example
    {
        public static void Main(string[] args)
        {
            FirefoxDriver session = new FirefoxDriver();

            session.ExecuteScript("window.open()");

            ReadOnlyCollection<string> currentWindowHandles = session.WindowHandles; 
        }
    }
}


Specifications

Specification Status Comment
WebDriver
The definition of 'Get Window Handles' in that specification.
Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome No support No
Notes
No support No
Notes
Notes To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabiliites when running the command.
Edge No support No
Notes
No support No
Notes
Notes The vendor-supported implementation for Edge is non-spec-conforming and incompatible.
Firefox Full support 55IE Full support 7Opera No support No
Notes
No support No
Notes
Notes To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabiliites when running the command.
Safari No support No
Notes
No support No
Notes
Notes The vendor-supported implementation for Safari is non spec-conforming and incompatible.
WebView Android No support No
Notes
No support No
Notes
Notes To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabiliites when running the command.
Chrome Android No support No
Notes
No support No
Notes
Notes To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabiliites when running the command.
Edge Mobile No support No
Notes
No support No
Notes
Notes The vendor-supported implementation for Edge is non-spec-conforming and incompatible.
Firefox Android No support NoOpera Android No support No
Notes
No support No
Notes
Notes To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabiliites when running the command.
Safari iOS No support No
Notes
No support No
Notes
Notes The vendor-supported implementation for Safari is non spec-conforming and incompatible.
Samsung Internet Android No support No
Notes
No support No
Notes
Notes The vendor-supported implementation for Samsung Internet is non-spec-conforming and incompatible.

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

See also

 

 

Document Tags and Contributors

Contributors to this page: MichaelTimbes, fscholz, ato
Last updated by: MichaelTimbes,