.window.getHandle() 建議編輯
檢索目前視窗的控制代碼。
WebDriver 不會區分視窗和索引標籤。 因此,如果您的網站開啟新的索引標籤或視窗,您可以使用視窗控制代碼來操作它。
用法
.window.getHandle([callback])
範例
module.exports = {
'get current window handle': function (browser) {
browser.window.getHandle(function (result) {
console.log('current window handle is:', result.value);
});
},
'get current window handle with ES6 async/await': async function (browser) {
const windowHandle = await browser.window.getHandle();
console.log('current window handle is:', windowHandle);
}
}
參數
名稱 | 類型 | 描述 |
---|---|---|
callback |
函式 | 呼叫時帶有結果值的回呼函式。 |
回傳
類型 | 描述 |
---|---|
字串 | 代表目前視窗的視窗控制代碼的唯一識別碼。 |