In IE: org.openqa.selenium.WebDriverException: This usually means that a call to the COM method IWebBrowser2::Navigate2() failed

后端 未结 4 977
情话喂你
情话喂你 2020-12-07 01:54

I am using Selenium to write test cases for my web application. When I run the test from Firefox it\'s working fine, but when I try to run it from IE I am not able to run an

4条回答
  •  伪装坚强ぢ
    2020-12-07 02:18

    This error message...

    org.openqa.selenium.WebDriverException: This usually means that a call to the COM method IWebBrowser2::Navigate2() failed
    

    ...implies that the IEDriverServer was unable to initiate/spawn a new Browsing Context i.e. Internet Explorer Browser session as a COM object.


    Protected Mode settings for Internet Explorer

    @JimEvans in a article You're Doing It Wrong: IE Protected Mode and WebDriver mentioned, while automating internet-explorer through iedriverserver:

    A browser session was represented by a single instance of the iexplore.exe executable. A framework for driving IE could instantiate the browser as a COM object using CoCreateInstance(), or could easily get the COM interfaces to a running instance by using the presence of ActiveAccessibility and sending a WM_HTML_GETOBJECT message to the appropriate IE window handle. Once the framework had a pointer to the COM interfaces, you could be sure that they'd be valid for the lifetime of the browser. It also meant you could easily attach to the events fired by the browser through the DWebBrowserEvents2 COM interface.Then along came the combination of IE 7 and Windows Vista. In and effort to reduce the attack surface presented by malicious web sites, IE 7 introduced something called Protected Mode, which leveraged Mandatory Integrity Control in Windows Vista to prevent actions initiated IE, usually initiated by JavaScript, from being able to access the operating system the way it could in prior releases. While this was generally a welcome development for most users of IE, it created all manner of problems for automating IE. When you cross into or out of Protected Mode by, say, navigating from an internal intranet website to one on the internet, IE has to create a new process, because it can't change the Mandatory Integrity Control level of the existing process. Moreover, in IE versions after 7, it's not always obvious that a Protected Mode boundary has been crossed, since IE tries to present a better user experience by seamlessly merging the browser window of the new process with the already opened browser window. This under-the-covers process switching also means that any references pointing to IE's COM objects before the Protected Mode boundary crossing are left pointing to objects that are no longer used by IE after the boundary crossing.


    Further, the Required Configuration of Internet Explorer Driver clearly mentions:

    • 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".

    ProtectedModeSettings

    • 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 Windows 10, you also need to set Change the size of text, apps, and other items to 100% in display settings.
    • 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 is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.
    • Note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Inside this key, create a DWORD value named iexplore.exe with the value of 0`.

    Solution

    First, you need to ensure that the Protected Mode settings for each zone to be the same value. Additionally you also need to ensure the Required Configuration for Internet Explorer Driver.


    References

    You can find a couple of relevant discussions in:

    • Internet Explorer Protective mode setting and Zoom levels
    • How does the registry entry HKEY_LOCAL_MACHINE\…\FEATURE_BFCACHE for InternetExplorerDriver solves the Internet Explorer 11 issue?
    • How to ignore zoom setting
    • Selenium InternetExplorerDriver doesn't get focus on the window
    • How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?

提交回复
热议问题