[英]Can this JavaScript handle more than one show/hide in a WordPress Page?
[英]Can I handle more than one modalDialog with Selenium?
我为使用ModalDialog窗口的旧应用程序编写了Selenium测试。 我知道如何使用一个ModalDialog进行处理:
在打开ModalDialog之前,我将其称为js-将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窗口中闪烁:正在发送请求,正在传输内容,正在读取内容),因此很明显Selenium找不到元素,因为未加载页面。
而且,如果我尝试在没有JS执行器的情况下打开第三个窗口,则会显示此错误:
引发异常:System.Reflection.TargetInvocationException:调用的目标引发了异常。 ---> OpenQA.Selenium.WebDriverException:URL URL到远程WebDriver服务器的HTTP请求http:// localhost:7057 / hub / session / c7e75043-9605-4f7c-80ac-233803527709 / element /%7B7664f1ae-9c42-4de6 -9e16-34fede6a9e26%7D /单击在60秒后超时。 ---> System.Net.WebException:该操作在System.Net.HttpWebRequest.GetResponse()处超时
我将Selenium v3.0.1与FireFox 45.6.0结合使用。
谢谢你的帮助!
为了能够处理下一个窗口,您应该使用以下方法将焦点切换回默认内容
_driver.SwitchTo().DefaultContent();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.