小编Ozo*_*one的帖子

selenium web驱动程序如何知道新窗口何时打开然后恢复执行

我在使用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); …

testing selenium window webdriver

27
推荐指数
2
解决办法
9万
查看次数

标签 统计

selenium ×1

testing ×1

webdriver ×1

window ×1