Set Window Rect
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
TheSet Window Rectcommand of theWebDriver API alters the size and position of the operating system window associated with the currentwindow
. The command acts as the setter ofGet Window Rect, which return object you can pass directly as this command's payload.
Certain subsets of devices do not support setting the window dimensions or its position. On these configurations the command will return anunsupported operating error. To avoid running into situations where calling this might error it is possible to call it conditionally on whether thesetWindowRect
capability is set to true for the session.
Setting the window rect takesx
,y
,width
, andheight
as input. All the fields are optional, e.g., the command may be called with an empty object, and in this case it will act as a no-op. To set the position both ofx
andy
are required, and correspondingly bothwidth
andheight
are required for altering the window's dimensions.
When setting the width or height, it is not guaranteed that the resulting window size will exactly match that which was requested. The driver is expected to clamp values that are larger than the physical screen dimensions, or smaller than the minimum window size. Some drivers may also have other limitations such as not being able to resize in single-pixel increments. For this reason, the returnedwidth
andheight
might not exactly matchWindow.outerWidth
andWindow.outerHeight
.
Setting the window's position is similar in nature to callingWindow.moveTo(x, y)
, but differences itself by bypassing security restrictions related to window manipulation.
The Set Window Rect command is blocking.
In this article
Syntax
Method | URI template |
---|---|
POST | /session/{session id}/window/rect |
URL parameters
session id
Identifier of the session.
Payload
The input is aWindowRect
object:
x
Horizontal position of the
window
, which equivalent toWindow.screenX
. Must be a number in the −(2^31) to 2^31 − 1 range, null, or undefined.y
Vertical position of the
window
, which is equivalent toWindow.screenY
. Must be a number in the −(2^31) to 2^31 − 1 range, null, or undefined.width
Outer width of the
window
, which is equivalent toWindow.outerWidth
. Must be a number in the 0 to 2^31 − 1 range, null, or undefined.height
Outer width of the
window
, which is equivalent toWindow.outerHeight
. Must be a number in the 0 to 2^31 − 1 range, null, or undefined.
Response
The response payload is aWindowRect
:
x
Horizontal position of the operating system window associated with
window
, equivalent toWindow.screenX
.y
Vertical position of the operating system window associated with
window
, equivalent toWindow.screenY
.width
Width of outer bounds of the operating system window associated with
window
, equivalent toWindow.outerWidth
.height
Height of the outer bounds of the operating system window associated with
window
, equivalent toWindow.outerHeight
.
Errors
- Invalid argument
If any of the fields in the
WindowRect
payload object do not meet the type or bounds constraints, or if only one of thex
/y
pair orwidth
/height
pair fields are specified.- Invalid session ID
Session does not exist.
- No such window
If the
window
has been closed.- Unexpected alert open
A user prompt, such as
window.alert
, blocks execution of command until it is dealt with.- Unsupported operation
If the driver does not support altering the window's size or position. This is usually the case on mobile devices, where the browser has a set dimension and cannot be moved around on the screen.
You can inspect the
setWindowRect
capability to tell if the device supports this command.
Specifications
Specification |
---|
WebDriver> # set-window-rect> |
Browser compatibility
Loading…
See also
WebWindow
object- Associated commands: