I found a problem trying to use Selenium WebDriver for testing our application. The issue is in unstable pop-ups focusing in IE9. It is not always reproducible, it takes place in about 20% of windows switching but makes testing on IE almost impossible. In FireFox everything works perfect.
- I try to increase timeout:
TimeSpan interval = new TimeSpan(0, 0, 10);
driver.Manage().Timeouts().ImplicitlyWait(interval);
Create own methods for objects finding:
for (int x = 0; x <= waitTimeOut; x++) { try { element = (IWebElement)driver.FindElement(By.XPath(obj.Xpath)); return element; } catch{} }
Try to use CssSelecotrs
Try to make some reswitching before finding element:
driver.SwitchTo().Window(GetWindowHandle(2, 1)); driver.SwitchTo().Window(GetWindowHandle(0, 1)); driver.SwitchTo().Window(GetWindowHandle(2, 1));
If the issue occurs, it always occurs only with the first element I try to find on the page. If the element is found there is no any problems with finding other elements on this page. So I decided the problem is in focusing.
Windows handles in debugger displays correctly. For example if I switches to the third window, driver.CurrentWindowHandle gives me correct handle of third window . But if I try to find any element, FindElement() throws me an exception. The page is loaded, I can click the element manually but FindElement() can't find it. If I rerun the test, this step can be passed without any problems and failed only at the next switching or further. It's unpredictable.
What can be the reason of such problem?