繁体   English   中英

Selenium 仅在 Headless 中运行 ChromeDriver

[英]Selenium ONLY Runs ChromeDriver in Headless

我有一个在 Firefox 中使用 Selenium 的工作 python 脚本,但是在尝试使用设置为驱动 Brave 的 chromedriver 运行相同的脚本时,它给出了错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /opt/brave.com/brave/brave is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

和调试日志:

DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:38723/session {"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"binary": "/opt/brave.com/brave/brave", "args": [], "extensions": []}, "browserName": "chrome", "platformName": "any"}, "firstMatch": [{}]}, "desiredCapabilities": {"goog:chromeOptions": {"binary": "/opt/brave.com/brave/brave", "args": [], "extensions": []}, "platform": "ANY", "browserName": "chrome", "version": ""}}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1:38723
DEBUG:urllib3.connectionpool:http://127.0.0.1:38723 "POST /session HTTP/1.1" 500 318
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request

但是,如果我只是添加一个无头参数,脚本会执行我想要它做的事情(减去 GUI):

from selenium import webdriver

driverPath = '/home/user/etc'
options = webdriver.ChromeOptions()
options.binary_location = '/opt/brave.com/brave/brave'
options.add_argument('--headless')
driver = webdriver.Chrome(executable_path=driverPath, options=options)

所以我想知道如何让 Brave 浏览器的 GUI 也运行。 我的驱动程序和浏览器版本是正确的。 二进制路径是正确的(我认为)。

我记得 Chrome headless 是在 Chrome59 中发布的。 因此,在您成功安装 chrome 后,您可以尝试从 shell 命令启动 chrome 并检查它是否安装正确。

chrome \
  --headless \                   # Runs Chrome in headless mode.
  https://stackoverflow.com      # URL to open.

chrome 二进制名称可以是 chrome 或 google-chrome 或其他明喻。

暂无
暂无

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

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