InternetExplorerDriver 的注册表项 HKEY_LOCAL_MACHINE\...\FEATURE_BFCACHE 如何解决 Internet Explorer 11 问题?

How does the registry entry HKEY_LOCAL_MACHINE\...\FEATURE_BFCACHE for InternetExplorerDriver solves the Internet Explorer 11 issue?

所以我在 IE11 中自动化了一个 Web 应用程序(为政府合同欢呼三声!)并且我按照 Selenium Wiki 上的说明来配置这个东西,因为我们有一堆奇怪和不稳定的行为。我在这一步很好,它说我已经添加了一个注册表项来帮助维持驱动程序和浏览器之间的连接:

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. Please note that the FEATURE_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 named iexplore.exe with the value of 0.

但这并不能真正解释为什么?如果您没有添加此密钥,会出现什么问题? "Maintain connection between an instance of IE and the webdriver" 一词可以表示很多不同的意思。

我们遇到的问题主要与 .click() 等 Selenium 方法有关,这些方法无法正常工作或无法点击参考点中感兴趣的页面。我们还有一些奇怪的滚动问题,当元素离开屏幕时它无法通过测试,这很奇怪,因为它应该读取 DOM,但我离题了。

你没看错。根据 InternetExplorerDriver Required Configuration 部分中的文档 明确提到:

仅对于 IE 11,您需要在目标计算机上设置注册表项,以便驱动程序可以保持与其创建的 Internet Explorer 实例的连接。

  • 对于 32 位 Windows 安装,您必须在注册表编辑器中检查的密钥是:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. 
    
  • 对于 64 位 Windows 安装,关键是:

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. 
    
  • 注意 FEATURE_BFCACHE 子项可能存在也可能不存在,并且应该在以下情况下创建它不存在。重要提示:在此键中,创建一个名为 iexplore.exe 的 DWORD 值,值为 0.

简史

根据@JimEvans 在讨论中的评论 IE11 exceptions with IEDriverServer: Unable to get browser

  • On 16 December 2014, Microsoft released update KB3025390 via Windows Update as part of its normal "patch Tuesday" update cycle. For most users, this update is downloaded and installed without user interaction. This update breaks the IE driver when using it with IE11.

  • As part of this update, attempting to use the COM method IHTMLWindow2::execScript returns an "access denied" result. This renders the driver unable to execute JavaScript in the page bring browsed. However, given that large portions of driver functionality are implemented using JavaScript, this effectively renders the driver all but unusable with IE11.

  • There is no known workaround for this issue. At this time, the Microsoft IE driver implementation is still incomplete, lacking basic functionality required to make it usable, so it cannot be recommended. Uninstalling the update might restore IE driver functionality, but this is hardly ideal.

  • While the execScript method is marked as deprecated for IE11, the driver had heretofore been able to use that method successfully, and it was hoped that it would remain useful throughout the IE11 life cycle. We now know this not to be the case. Additionally, attempts to use the Microsoft-suggested replacement, eval, have been fruitless thus far.

  • The issue is currently being tracked in the Selenium issue tracker.

  • 在此讨论中@JimEvans 进一步添加了评论:

The registry entry disables a caching feature of IE called BFCache, which affects how pages are cached and loaded when using forward and backward navigation feature of the browser. When enabled, the COM objects on which the driver relies (yes, the very same objects used by the mshtml library) become orphaned if you navigate back or forward. There are other ways to increase the “reliability” of the driver’s click() method.