Get Window Rect

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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 optimization 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
WebDriver
# get-window-rect

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
GetWindowRect
Chrome – Full support
Chrome 65 (Release date: 2018-03-06)
footnote
footnote To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabilities.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabilities.
Firefox – Full support
Firefox 55 (Release date: 2017-08-08)
footnote Full support
Opera – No support
Opera
footnote
footnote To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabilities.
Safari – No support
Safari
footnote
footnote The vendor-supported implementation for Safari is non spec-conforming and incompatible.
Chrome Android – No support
Chrome Android
footnote
footnote To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabilities.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote
footnote To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabilities.
Safari on iOS – No support
Safari on iOS
footnote
footnote The vendor-supported implementation for Safari on iOS is non spec-conforming and incompatible.
Samsung Internet – No support
Samsung Internet
footnote
footnote The vendor-supported implementation for Samsung Internet is non-spec-conforming and incompatible.
WebView Android – No support
WebView Android
footnote
footnote To enable Chromium support, include {"goog:chromeOptions": {"w3c": true}} in the capabilities.
WebView on iOS – No support
WebView on iOS
footnote
footnote The vendor-supported implementation for WebView on iOS is non spec-conforming and incompatible.

Legend

Tip: you can click/tap on a cell for more information.

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

See also