Working with Selenium tests for an old application that utilizes ModalDialog windows can be tricky. Handling one ModalDialog is straightforward:
Before opening the ModalDialog, I use this JavaScript to change the window properties:
((IJavaScriptExecutor) _driver).ExecuteScript("window.showModalDialog = window.open;");
After opening the ModalDialog, switching to that window and handling it is achievable:
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; } } }
However, encountering a second ModalDialog issue (when already in a third window) presents challenges:
An exception was thrown: OpenQA.Selenium.NoSuchElementException: Could not find element by: By.Id: btnClearSearchName
In Firefox, there are loading issues indicated by window flashing. This results in Selenium being unable to locate elements due to incomplete page loading.
Attempting to open a third window without using JS executor lead to this error message:
An exception occurred: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:7057/hub/session/c7e75043-9605-4f7c-80ac-233803527709/element/%7B7664f1ae-9c42-4de6-9e16-34fede6a9e26%7D/click timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()
I am using Selenium v3.0.1 with FireFox 45.6.0.
Your assistance is greatly appreciated!