如何在量角器中关闭浏览器的当前选项卡而不关闭整个浏览器 [英] How to close the current tab of the browser in protractor with out closing the complete browser

查看:14
本文介绍了如何在量角器中关闭浏览器的当前选项卡而不关闭整个浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序中,我有两个选项Google,Twitter";.当我点击任何选项时,它将在新标签中打开.

In the application i have two options "Google , Twitter" . When i click on any option it will open in new tab.

在我的测试用例中,我想点击 google 或 twitter 选项并关闭 google 或 twitter 选项卡并返回到我的应用程序.

In my test case , i would like to click on google or twitter option and close the google or twitter tab and return back to the my application.

有没有办法只关闭新打开的标签.

Is there any way to close only newly opened tab.

我尝试了以下解决方案.

I tried below solutions.

browser.close(); 正在关闭整个浏览器.

browser.close(); is closing the entire browser.

谁能帮助我如何只关闭浏览器的标签(在我的例子中是谷歌标签或推特标签)而不用量角器关闭整个浏览器

Can any one help me how to close only tab of the browser ( in my case google tab or twitter tab) with out closing the entire browser in protractor

推荐答案

您可以尝试以下方法:

切换到新打开的标签.关闭当前窗口(在本例中为新选项卡).切换回第一个窗口.

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((handles) => {
    browser.driver.switchTo().window(handles[1]);
    browser.driver.close();
    browser.driver.switchTo().window(handles[0]);
});

这篇关于如何在量角器中关闭浏览器的当前选项卡而不关闭整个浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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