Headless_ie_driver 启动 Internet Explorer 时出现意外错误。 IELaunchURL() 返回 HRESULT 80070012 ('There are no more files.')

Headless_ie_driver Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.')

我正在尝试 运行 一个简单的无头网络浏览器;

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Ie("headless_ie_selenium.exe")
driver.get("www.google.com")
print(driver.title)

我得到:

selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:65393/'

我尝试过但没有奏效的方法:

1:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
caps['ie.ensureCleanSession']= True
driver = webdriver.Ie("headless_ie_selenium.exe",capabilities=caps)

2:所有Internet Options Security设置都在同一级别,并且都勾选了Enabled Protected Mode;

3: 搜索了一个C:\Program文件夹删除,但是没有。

注意事项:同样的代码在普通的 webdriver (IEDriverServer.exe) 上运行良好,当我打开 headless_ie_selenium.exe 手动启动:

Selenium driver found at: path..\IEDriverServer.exe
Started InternetExplorerDriver server (32-bit)
3.8.0.0

您看到的错误说明了一切:

selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:65393/'

如果您访问 Release Page of headless-selenium-for-win the Release Notes for headless-selenium-for-win v1.4,它会清楚地提到以下内容:

  • 支持 Firefox 和 Chrome
  • Windows 资源管理器不再在无头桌面中启动。
  • desktop_utils.exe 学会了在创建无头桌面后 运行 explorer.exe。

因此 Internet Explorer 不能用 headless_ie_selenium.exe.

初始化

更新:

根据您的评论 Are there any alternatives to open IE and run it in background via selenium with mouse/keyboard inputsAnswer

@JimEvans 在 Github 线程 Headless IE with selenium not working on Windows server 中明确提到:

The IE driver does not support execution without an active, logged-in desktop session running. You'll need to take this up with the author of the solution you're using to achieve "headless" (scare quotes intentional) execution of IE.

他还补充说:

Mouse and keyboard simulation won't work without an active session. It's a browser limitation, not a driver limitation.