I believe I may have found the solution. I went into IE -> Internet options -> Advanced -> Reset Internet Explorer Settings. After doing this and rebooting, I no longer have the issue with window-switching. I'm not sure why this happened, because I hardly use IE; I can't imagine that I changed any important settings.
During this process, I noticed a few issues which may be relevant. To be absolutely transparent, I will state everything that I did.
After resetting my settings, when I first opened IE, I answered a few dialogs. First, I clicked "Use recommended security and compatibility settings" and "OK". Then, under "Would you like to make Internet Explorer your default browser?", I clicked "No" and "Don't ask again". Finally, for "Several add-ons are ready for use", I clicked "Don't enable".
Then, when I attempted to run a program, using the 64-bit driver. (I am assuming that my IE is 64-bit, because in the Start Menu, the program is under C:Program Files
-- not C:Program Files (x86)
, like some of my other programs.) It would crash on the line IWebDriver driver = new InternetExplorerDriver();
. The error was as follows:
InvalidOperationException was unhandled
Unexpected error launching Internet Explorer. Protected Mode settings are not
the same for all zones. Enable Protected Mode must be set to the same value
(enabled or disabled) for all zones. (NoSuchDriver)
To fix this, I went into IE -> Internet options -> Security and checked "Enable Protected Mode" for all four zones. This fixed it; when I ran my program, I no longer got that error. This problem (that the IE driver does not work with the default settings of IE 10) may be an issue worth documenting.
After changing those settings, my program ran -- but it did so extremely slowly. It literally took 60 seconds to type six-character-long strings into two text boxes. I then switched to the 32-bit driver (despite having 64-bit IE), and it runs at normal speed.
Finally, I ran my program all the way through, and it no longer drops window handles.
To summarize: If you're having issues with the IE driver dropping window handles, consider resetting your IE settings. That seems to have fixed it for me.