Headless_ie_driver启动Internet Explorer时出现意外错误。 IELaunchURL()返回HRESULT 80070012('没有更多文件。')

时间:2018-01-18 13:39:03

标签: python selenium selenium-webdriver headless headless-browser

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

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选项安全设置都处于同一级别,并且都已选中启用保护模式;

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

1 个答案:

答案 0 :(得分:1)

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

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 headless-selenium-for-win Release Notes headless-selenium-for-win v1.4,则会明确提及以下内容:

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

因此无法使用 headless_ie_selenium.exe 初始化 Internet Explorer

更新:

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

@ GimEvans在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.