我正在尝试运行一个简单的无头网络浏览器;
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
答案 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
,则会明确提及以下内容:
因此无法使用 headless_ie_selenium.exe 初始化 Internet Explorer 。
根据您的评论Are there any alternatives to open IE and run it in background via selenium with mouse/keyboard inputs
,Answer
是否。
@ 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.
强>