Set Window Rect
The Set Window Rect command of the WebDriver API alters the size and position of the operating system window associated with the current
window. The command acts as the setter of Get 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 an unsupported operating error. To avoid running into situations where calling this might error it is possible to call it conditionally on whether the
setWindowRect capability is set to true for the session.
Setting the window rect takes
height 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 of
y are required, and correspondingly both
height 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 returned
height might not exactly match
Setting the window's position is similar in nature to calling
Window.moveTo(x, y), but differences itself by bypassing security restrictions related to window manipulation.
The Set Window Rect command is blocking.
Identifier of the session.
The input is a
The response payload is a
- Invalid argument
If any of the fields in the
WindowRectpayload object do not meet the type or bounds constraints, or if only one of the
heightpair fields are specified.
- Invalid session ID
Session does not exist.
- No such window
windowhas 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
setWindowRectcapability to tell if the device supports this command.
BCD tables only load in the browser