我正在尝试运行一个简单的无头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
您所看到的错误说明了一切:
如果您访问Release Page的 headless-selenium-for- win 的Release Notes为 headless-selenium-for-win v1.4 它明确提到了以下情况:
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是 无 。
Are there any alternatives to open IE and run it in background via selenium with mouse/keyboard inputs
Answer
Github线程中的@JimEvans Headless IE with selenium not working on Windows server 明确提到:
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.