This is related to my other recent question on Selenium (that question was about a Firefox-specific issue, this one is about an IE-specific issue).
Basically, when I ran the following code
ieDriver.Navigate().GoToUrl("http://localhost:51282");
IWebElement linkToAboutPage = ieDriver.FindElement(By.Id("test"));
linkToAboutPage.Click();
to simulate clicking on a link, it successfully navigates to the page but when it tries to retrieve the actual element I get the following exception:
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to find element on closed window
The accepted answer to this question suggests that "Enable Protected Mode" in IE Security Settings should either be all selected or all unselected. Indeed, when I look at these settings, "Enable Protected Mode" is unselected for Intranet but not for the others:
Unfortunately, as the screenshot shows, that's being managed by my corporate IT department and I'm not sure that I'll have much luck convincing them to let me change the settings. I was also unable to edit my registry in the way suggested by some of the other answers (presumably due to the lack of administrative rights).
Some of the other solutions I've seen include setting IntroduceInstabilityByIgnoringProtectedModeSettings
to true
, providing a InitialBrowserUrl
, or setting EnsureCleanSession
to true
. As shown below, I'm currently doing all of those things:
var ieOptions = new InternetExplorerOptions()
{
InitialBrowserUrl = "http://www.google.com",
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
IgnoreZoomLevel = true,
EnableNativeEvents = true,
EnsureCleanSession = true
};
ieDriver = new InternetExplorerDriver(ieOptions);
ieDriver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 10);
However, I'm still having the exact same problem.
Is there something else I can try that doesn't involve me bugging corporate IT for policy exceptions?
Perhaps significantly, this only happens when I'm running on localhost
(which is a problem because that's where I intend to do most of my testing).
I found that setting the InitialBrowserUrl
capability to the starting URL you want to navigate to, paired with IntroduceInstabilityByIgnoringProtectedModeSettings = true
, works for me.
var ieOptions = new InternetExplorerOptions()
{
InitialBrowserUrl = <your-starting-url>
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
...
};
Unfortunately I don't have a reason as to why this works, so this "fix" might simply be anecdotal...
Here's some other solutions you can try (from the official reference):
Required Configuration
- The IEDriverServer exectuable must be downloaded and placed in your PATH.
- On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
- Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
- The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
- For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
. For 64-bit Windows installations, the key isHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
. Please note that theFEATURE_BFCACHE
subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value namediexplore.exe
with the value of 0.
Reference:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With