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

后端 未结 8 1277
悲&欢浪女
悲&欢浪女 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条回答
  •  半阙折子戏
    2020-12-01 06:44

    C# Version of Sakshi's answer:

       var tabs = driver.WindowHandles;
       if (tabs.Count > 1)
       {
           driver.SwitchTo().Window(tabs[1]);
           driver.Close();
           driver.SwitchTo().Window(tabs[0]);
       }
    

提交回复
热议问题