【发布时间】:2017-05-20 23:37:45
【问题描述】:
我为使用 ModalDialog 窗口的旧应用程序编写 Selenium 测试。我知道如何处理一个 ModalDialog:
-
在打开 ModalDialog 之前,我称之为 js - 将 window pro ModalDialog 更改为经典窗口:
((IJavaScriptExecutor) _driver).ExecuteScript("window.showModalDialog = window.open;"); -
打开 ModalDialog 后,我切换到该窗口,我可以处理它:
public static void SwitchToWindow(IWebDriver _driver, string url) { String parentWindowHandle = _driver.CurrentWindowHandle; IWebDriver popup = null; var windowIterator = _driver.WindowHandles; foreach (var windowHandle in windowIterator) { popup = _driver.SwitchTo().Window(windowHandle); if (popup.Url.Contains(url)) { break; } } }
但如果我想使用第二个 ModalDialog 来执行此操作(所以我现在在第三个窗口中)我遇到了这个问题:
抛出异常: OpenQA.Selenium.NoSuchElementException:找不到元素:By.Id:btnClearSearchName
(在 Firefox 窗口中闪烁:Sending request to, Transfering something, Read something)所以很明显 Selenium 找不到元素,因为页面没有加载。
如果我之前尝试在没有 JS 执行器的情况下打开第三个窗口,则会显示此错误:
抛出异常: System.Reflection.TargetInvocationException:调用的目标已引发异常。 ---> OpenQA.Selenium.WebDriverException:对 URL http://localhost:7057/hub/session/c7e75043-9605-4f7c-80ac-233803527709/element/%7B7664f1ae-9c42-4de6-9e16-34fede6a9e26%7D/click 的远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时。 ---> System.Net.WebException:操作已超时 在 System.Net.HttpWebRequest.GetResponse()
我使用 Selenium v3.0.1 和 FireFox 45.6.0。
感谢您的帮助!
【问题讨论】:
标签: javascript c# selenium showmodaldialog