Is there a way to close a tab in WebDriver or Protractor?

后端 未结 8 1278
悲&欢浪女
悲&欢浪女 2020-12-01 06:37

Is there a way to physically close a tab via Protractor or WebDriver?

I ask because while I know how to switch tabs programmatically, but it does not bring the acti

8条回答
  •  猫巷女王i
    2020-12-01 07:02

    You can try the following:

    1. Switch to the new opened tab.
    2. Close the current windows (in this case, the new tab).
    3. 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]);
      });
      

提交回复
热议问题