When using Selenium with Intrenet Explorer 11, a common error encountered is:
OpenQA.Selenium.NoSuchWindowException: Unable to find element on closed window
This issue occurs becuase IE11 does not fully support Selenium 2.0's WebDriver protocol, particularly when trying to locate elements on a page.
Solution: Modify Windows Registry
For IE 11 specifically, you need to set a registry entry on the target machine to allow the driver to maintain a connection with the Internet Explorer instance it creates.
Steps:
-
Open the Registry Editor by pressing
Win + R, typingregedit, and pressing Enter. -
Navigate to the appropriate registry key based on your Windows version:
-
For 32-bit Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE -
For 64-bit Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
-
-
If the
FEATURE_BFCACHEsubkey does not exist underFeatureControl, create it by right-clicking and selecting New → Key. Name it exactlyFEATURE_BFCACHE. -
Inside the
FEATURE_BFCACHEkey, create a new DWORD (32-bit) value:- Name:
iexplore.exe - Value:
0
- Name:
-
Close the Registry Editor and restart your computer for the changes to take effect.
-
After restarting, launch your development environment (e.g., Visual Studio, Eclipse) as an Administrator. Running without administrator privileges may cause the error to persist.
-
Run your project again. The element-finding issue should now be resolved.