本文介紹了量角器切換到上一個選項卡的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
打開一個新標簽(第二個)后,我試圖切換到第一個標簽.
After opening a new tab (second) I'm trying to switch to the first tab.
common.clickOpenNewSession(); //it opens the new tab
browser.getAllWindowHandles().then(function (handles) {
var secondWindowHandle = handles[1];
var firstWindowHandle = handles[0];
browser.switchTo().window(secondWindowHandle).then(function () { //the focus moves on new tab
browser.sleep(3000);
expect(browser.driver.getCurrentUrl()).toContain("url");
//do some actions
});
//below it doesn't work. I try to go back on previous tab without closing the second tab
browser.actions().sendKeys(protractor.Key.CONTROL).sendKeys(protractor.Key.TAB).perform();
browser.sleep(4000);
browser.driver.switchTo().window(firstWindowHandle);
browser.setLocation('http://google.com');
});
推薦答案
問題是你試圖通過使用 ctrl + tab 轉到上一個選項卡,而不是使用窗口句柄切換回來.這在 WebDriver 中不受支持,因為使用 ctrl + tab 是一種系統操作,不能在您的瀏覽器上為所有操作系統/瀏覽器模擬.只需再次使用 browser.switchTo()
.
The problem is that you're trying to go to the previous tab by using ctrl + tab, instead of using the window handles to switch back. This is not supported in WebDriver, because using ctrl + tab is a system operation, and can't be emulated on your browser for all OS/browsers. Just use browser.switchTo()
again.
這篇關于量角器切換到上一個選項卡的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!