一尘不染

Headless_ie_driver启动Internet Explorer时发生意外错误。IELaunchURL()返回HRESULT 80070012(“没有其他文件。”)

selenium

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

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文件夹,但是没有任何内容。

注意 :相同的代码对于普通的网络驱动程序(IEDriverServer.exe)可以正常工作,当我手动打开
headless_ie_selenium.exe时 ,它将启动:

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

阅读 930

收藏
2020-06-26

共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- winRelease 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

Github线程中的@JimEvans 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.

2020-06-26