量角器切换到上一个选项卡
打开一个新标签(第二个)后,我试图切换到第一个标签.
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.
相关文章