找不到窗口 - NoSuchWindowException未处理

时间:2012-11-06 19:19:55

标签: selenium selenium-webdriver

我收到错误消息No Window found我正在尝试切换到窗口,下面是我正在使用的代码。

        VisitMyWebSite();

        string originalHandle = driver.CurrentWindowHandle;

        IWebElement addtoList = driver.FindElement(By.XPath(_pageName));
        addtoList.Click();

        ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
        string popupHandle = string.Empty;

        foreach (string handle in windowHandles)
        {
            if (handle != originalHandle)
            {
                popupHandle = handle; break;
            }
        }

        Thread.Sleep(4000);

        //switch to new window 
        driver.SwitchTo().Window(popupHandle);  //error No Window found

0 个答案:

没有答案