更改目前視窗的 視窗矩形 - 大小和位置。

其 JSON 表示法如下

  • x - 視窗的 screenX 屬性;
  • y - 視窗的 screenY 屬性;
  • width - outerWidth 屬性;
  • height - outerHeight 屬性。

所有屬性均以 CSS 像素為單位。

若要變更視窗矩形,您可以一起指定 widthheight,一起指定 xy,或一起指定所有屬性。

用法

                    .window.setRect({width, height, x, y}, [callback])
                

範例

module.exports = {
  'set current window rect': function (browser) {
     // Change the screenX and screenY attributes of the window rect.
     browser.window.setRect({x: 500, y: 500});

     // Change the outerWidth and outerHeight attributes of the window rect.
     browser.window.setRect({width: 600, height: 300});
  },

  'set current window rect using ES6 async/await': async function (browser) {
     // Change all attributes of the window rect at once.
     await browser.window.setRect({
       width: 600,
       height: 300,
       x: 100,
       y: 100
     });
  }
}

參數

名稱 類型 描述
options Object

一個物件,指定 widthheightxy,或全部一起設定 視窗矩形 的屬性。

callback
可選
function

命令完成時呼叫的可選回呼函數。

另請參閱

W3C WebDriver 規格