Microsoft's Internet Explorer is a notoriously difficult browser to run automated tests against. Part of this is because IE is comparatively slow compared to other browsers, so it's possible for your script to outrun the browser in searching for an element in the DOM, resulting in synchronization issues, especially if you are using JavaScript test suites with the 64-bit version. This is often the reason why a script works fine in Chrome or Firefox, but fails against IE with a NoSuchElementFound
exception. There can also be issues with using CSS selectors in older versions of IE, and with mouse events. This article will provide you with some common tips and tricks for testing against IE with Selenium, as well as some links to additional resources.
Synchronization Issues and WebDriverWait
The best way to deal with synchronization issues is to use one of the WebDriverWait methods in your test script. These allow you to specify a condition within your test and then wait for that condition to be true before proceeding to the next step. It's also a Sauce Labs recommended best practice to use explicit waits in your tests.
Using CSS Selectors with Older Versions of IE
Current versions of IE support CSS 3 selectors, but versions 7 and 8 only support General Siblings and Attribute selectors. If you need to test against these versions of IE, you will need to use different selectors.
Native Events, Browser Focus, and Mouse Events
As described in detail in the InternetExplorerDriver documentation, the driver uses native Windows events to perform mouse and keyboard operations. Several issues have arisen, however, that result in unexpected behavior. If any IE driver commands show instability, try re-testing using JavaScript.
- If you attempt to hover over elements and your physical mouse cursor is within the boundaries of the IE browser window, the hover state will appear for an instant and then disappear. There is no known workaround for this behavior.
- If the test involves clicking an
<option>
element within a<select>
element, and theOnChange
event of the<select>
element callsalert()
,confirm()
, orprompt()
, calling WebElement'sclick()
method will result in a hang until the modal dialog is dismissed. This is because the IE driver normally calculates where to click based on the position and size of an element as returned by thegetBoundingClientRectangle()
method, but for<option>
elements this will return a rectangle with zero position and zero size. To counteract this, the driver uses theclick()
Automation Atom instead of a native event to set the.selected
property of the<option>
element and simulate theonChange
event in JavaScript. This same situation can arise when submitting an HTML form by using theWebElement submit()
method.
Additional Resources
- Internet Explorer Driver Documentation at SeleniumHQ
All the most up-to-date documentation for the IE Driver, along with a download link and configuration information - Test Talks Podcast #28: Jim Evans with Secrets on How to Succeed with Selenium and IE
Joe Colantonio in conversation with Jim Evans, developer of the .NET bindings for Selenium and the IE Driver, sponsored by Sauce Labs - Selenium and IE - Getting Them to Work Together
A summary blog post of Joe Colantonio's conversation with Jim Evans