简体   繁体   English

Internet Explorer 无法在 Selenium 的无头模式下工作 [使用 headless_ie_selenium]

[英]Internet Explorer NOT working in headless mode with Selenium [Using headless_ie_selenium]

I am aware that IE does not support headless.我知道 IE 不支持无头。 But there's a workaround of using virtual desktops on Windows to get it done.但是有一种解决方法是在 Windows 上使用虚拟桌面来完成它。 This is what https://github.com/kybu/headless-selenium-for-win is doing, but I seem to be running into an issue here.这就是https://github.com/kybu/headless-selenium-for-win正在做的事情,但我似乎在这里遇到了问题。

My IEDriverServer.exe is added to $PATH$, and headless_ie_selenium.exe is also in the same directory as the IEDriverServer.exe我的IEDriverServer.exe添加到$PATH$,headless_ie_selenium.exe也和IEDriverServer.exe在同一个目录下

I'm trying to use it like this:我正在尝试像这样使用它:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Ie('C:\IEDriverServer_Win32_3.150.1\headless_ie_selenium.exe')

browser.get('www.someurl.com')

I'm pasting the traceback below我在下面粘贴回溯

Traceback (most recent call last):
  File "C:\Users\hjind\Desktop\pythonRCM\headless_ie.py", line 16, in <module>
    browser = webdriver.Ie('C:\IEDriverServer_Win32_3.150.1\headless_ie_selenium.exe')
  File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\ie\webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:57762/'

The only thing that worked for me was to programatically minimise the IE window on launch, and switch to another virtual desktop while the job runs.唯一对我有用的是在启动时以编程方式最小化 IE window,并在作业运行时切换到另一个虚拟桌面。

Setting introduce_flakiness_by_ignoring_security_domains helped bypass the "Protected Mode" and "Zoom Level" errors.设置introduce_flakiness_by_ignoring_security_domains有助于绕过“保护模式”和“缩放级别”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM