有没有办法关闭WebDriver或Protractor中的选项卡? [英] Is there a way to close a tab in WebDriver or Protractor?
本文介绍了有没有办法关闭WebDriver或Protractor中的选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过量角器或WebDriver物理关闭选项卡?
Is there a way to physically close a tab via Protractor or WebDriver?
我问,因为虽然我知道如何切换标签,但是它确实不要将活动选项卡置于前台.我无法总是说出在SauceLabs上进行的E2E测试中发生了什么,因为当我查看屏幕投射时,它显示的是我离开的选项卡,而不是活动的选项卡.
I ask because while I know how to switch tabs programmatically, but it does not bring the active tab to the foreground. I can't always tell what is going on in my E2E tests that run on SauceLabs because when I view the screen casts it is showing the tab that I navigated away from, not the active one.
我会错误地处理此问题吗?
Am I going about this incorrectly?
it('should do something in the previous tab', function(done) {
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
// do something
expect(something).toEqual(thisThing);
done();
});
});
推荐答案
您可以尝试以下操作:
- 切换到新打开的标签.
- 关闭当前窗口(在本例中为新选项卡).
-
切换回第一个窗口.
- Switch to the new opened tab.
- Close the current windows (in this case, the new tab).
Switch back to the first window.
browser.getAllWindowHandles().then(function (handles) {
browser.driver.switchTo().window(handles[1]);
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});
这篇关于有没有办法关闭WebDriver或Protractor中的选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文