问题
I'm trying to run a simple headless web-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)
And I'm getting:
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:65393/'
What I've tried but didn't work:
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: All Internet Options Security settings are at the same level and all have checked Enabled Protected Mode;
3: Searched for a C:\Program folder to delete, but there was nothing.
Notes: The same code works fine with the normal webdriver (IEDriverServer.exe), and when I open the headless_ie_selenium.exe manually it starts:
Selenium driver found at: path..\IEDriverServer.exe
Started InternetExplorerDriver server (32-bit)
3.8.0.0
回答1:
The error you are seeing says it all :
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:65393/'
If you visit the Release Page of headless-selenium-for-win the Release Notes
for headless-selenium-for-win v1.4 it clearly mentions the following :
- Supporting Firefox and Chrome
- Windows explorer is not started anymore in the headless desktop.
- desktop_utils.exe learned to not run explorer.exe after a headless desktop is created.
Hence Internet Explorer can't be initialized with headless_ie_selenium.exe.
Update :
As per your comment Are there any alternatives to open IE and run it in background via selenium with mouse/keyboard inputs
the straight Answer
is No.
@JimEvans in the Github Thread Headless IE with selenium not working on Windows server clearly mentions that :
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.
He also adds :
Mouse and keyboard simulation won't work without an active session. It's a browser limitation, not a driver limitation.
来源:https://stackoverflow.com/questions/48322719/headless-ie-driver-unexpected-error-launching-internet-explorer-ielaunchurl-r