Selenium IE9 WaitForPageToLoad Fix
There appears to be an issue in Selenium that causes WaitForPageToLoad to act improperly in IE9.
To resolve the issue copy the following code into a file called "user-extensions.js":
Reference that file when you start the Selenium server using the "-userExtensions" option:
java -jar selenium-server-standalone-2.4.0.jar -userExtensions user-extensions.js
Now for the explanation...
I noticed that when I experienced the WaitForPageToLoad timeout, the browser logs showed an unusual error message coming from IEBrowserBot.windowclosed:
debug(1314123427103): _isSamePage: sameLoc: true debug(1314123427103): _isSamePage: sameHref: true debug(1314123427103): _isSamePage: markedLoc: true debug(1314123427824): replaced getReadyState used debug(1314123427824): pageUnloading = true!!!! debug(1314123427824): getReadyState returning loading debug(1314123427824): pollForLoad continue (selenium1314123422376): undefined debug(1314123427824): runScheduledPollers DONE debug(1314123427843): runScheduledPollers debug(1314123427843): IEBrowserBot.pollForLoad: selenium1314123422376 debug(1314123427843): pollForLoad original (selenium1314123422376): http://localhost:8000/weblo/Gfe.aspx debug(1314123427899): IEBrowserBot.windowClosed: couldn't read win.document, assume closed: (this.pageUnloading=true) debug(1314123427899): pollForLoad WINDOW CLOSED (selenium1314123422376) debug(1314123427899): runScheduledPollers DONE debug(1314123427900): runScheduledPollers debug(1314123427900): runScheduledPollers DONE debug(1314123427919): runScheduledPollers debug(1314123427919): runScheduledPollers DONE
Looking at browser-bot.js, I noticed that the condition with the logged error "couldn't read win.document, assume closed" is the only one that returns true:
I changed that to return false and included the entire function as a user extension, thus overwriting the original:
Since then, I have run over a thousand tests (on IE9) and not one has faltered because of WaitForPageToLoad.
Labels: IE9, Internet Explorer 9, page load, pageload, Selenium, Wait for page to load, WaitForPageToLoad
# posted by Greg @ 8/26/2011 08:13:00 PM
Post a Comment