Set Window Rect - WebDriver 编辑

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 x, y, width, and 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 x and y are required, and correspondingly both width and height are required for altering the window’s dimensions.

When setting the width or height, it is not guarnateed 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 width and height might not exactly match Window.outerWidth and Window.outerHeight.

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.

Syntax

MethodURI template
POST/session/{session id}/window/rect

URL parameters

session id
Identifier of the session.

Payload

The input is a WindowRect object:

x
Horizontal position of the window, which equivalent to Window.screenX. Must be a number in the −(231) to 231 − 1 range, null, or undefined.
y
Vertical position of the window, which is equivalent to Window.screenY. Must be a number in the −(231) to 231 − 1 range, null, or undefined.
width
Outer width of the window, which is equivalent to Window.outerWidth. Must be a number in the 0 to 231 − 1 range, null, or undefined.
height
Outer width of the window, which is equivalent to Window.outerHeight. Must be a number in the 0 to 231 − 1 range, null, or undefined.

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 argument
If any of the fields in the WindowRect payload object do not meet the type or bounds constraints, or if only one of the x/y pair or width/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

SpecificationStatusComment
WebDriver
The definition of 'Set Window Rect' in that specification.
Living StandardInitial definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:138 次

字数:8753

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文