Get Window Rect

The Get Window Rect command of the WebDriver API returns the size and position of the given WebElement. Many WebDriver clients present separate API methods for getting an element’s location and dimensions, but as an optimisation they both use this primitive.

The command operates on the currently selected window, and returns size and position of the operating system window. The returned WindowRect can be used as input for the Set Window Rect command, which is for manipulating a window’s position and dimensions.

Syntax

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

URL parameters

session id
Identifier of the session.

Response

The response payload is a WindowRect:

x
Horizontal position of the operating system window associated with window, equivalent to Window.screenX.
y
Vertical position of the operating system window associated with window, equivalent to Window.screenY.
width
Width of outer bounds of the operating system window associated with window, equivalent to Window.outerWidth.
height
Height of the outer bounds of the operating system window associated with window, equivalent to Window.outerHeight.

Errors

Invalid session ID
Session does not exist.
Unexpected alert open
A user prompt, such as window.alert, blocks execution of command until it is dealt with.

Specifications

Specification Status Comment
WebDriver
The definition of 'Get Window Rect' 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: fscholz, ato
Last updated by: fscholz,