Selenium webdriver window handles c# switchTo failed

后端 未结 5 1256
广开言路
广开言路 2021-02-10 02:11

Here comes 2 windows pop out during the testing.

my code:

string BaseWindow = driver.CurrentWindowHandle;                 
ReadOnlyCollection

        
5条回答
  •  醉酒成梦
    2021-02-10 02:46

            IWebDriver popup = null;
            string mainWindow = driver.CurrentWindowHandle;
            bool foundPopupTitle = false;
            foreach (string handle in driver.WindowHandles)
            {
                popup = driver.SwitchTo().Window(handle);
                if (popup.Title.Contains(title))
                {
                    foundPopupTitle = true;
                    break;
                }
            }
    
            if (foundPopupTitle)
            {
                popup.Close();
            }
            //switch back to original window
            driver.SwitchTo().Window(mainWindow);
    

提交回复
热议问题