我在使用selenium web驱动程序自动化Web应用程序时遇到了问题.
该网页有一个按钮,单击该按钮可打开一个新窗口.当我使用以下代码时,它会抛出OpenQA.Selenium.NoSuchWindowException: No window found
WebDriver.FindElement(By.Id("id of the button that opens new window")).Click();
//Switch to new window
_WebDriver.SwitchTo().Window("new window name");
//Click on button present on the newly opened window
_WebDriver.FindElement(By.Id("id of button present on newly opened window")).Click();
Run Code Online (Sandbox Code Playgroud)
为解决上述问题,我Thread.Sleep(50000);在按钮单击和SwitchTo语句之间添加.
WebDriver.FindElement(By.Id("id of the button that opens new window")).Click();
Thread.Sleep(50000); //wait
//Switch to new window
_WebDriver.SwitchTo().Window("new window name");
//Click on button present on the newly opened window
_WebDriver.FindElement(By.Id("id of button present on newly opened window")).Click();
Run Code Online (Sandbox Code Playgroud)
它解决了这个问题,但我不想使用该Thread.Sleep(50000); …