量角器切换到上一个选项卡 [英] protractor switch to previous tab

查看:20
本文介绍了量角器切换到上一个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开一个新标签(第二个)后,我试图切换到第一个标签.

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.

这篇关于量角器切换到上一个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆