简体   繁体   English

Selenium 仅在 Headless 中运行 ChromeDriver

[英]Selenium ONLY Runs ChromeDriver in Headless

I have a working python script that uses Selenium with Firefox, but in attempting to run the same script just with a chromedriver set to drive Brave, it gives the error:我有一个在 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.)

And debug log:和调试日志:

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

However, the script does what I want it to do (minus the GUI) if I just add a headless argument:但是,如果我只是添加一个无头参数,脚本会执行我想要它做的事情(减去 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)

So I am wondering how to get the Brave browser's GUI to run as well.所以我想知道如何让 Brave 浏览器的 GUI 也运行。 My driver and browser versions are correct.我的驱动程序和浏览器版本是正确的。 The binary path is correct (I think).二进制路径是正确的(我认为)。

as I remember Chrome headless was shipped in Chrome59.我记得 Chrome headless 是在 Chrome59 中发布的。 So after you successfully installed chrome, can you try to launch chrome from the shell command and check if it's correct installed.因此,在您成功安装 chrome 后,您可以尝试从 shell 命令启动 chrome 并检查它是否安装正确。

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

The chrome binary name may be chrome or google-chrome or other similes. chrome 二进制名称可以是 chrome 或 google-chrome 或其他明喻。

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

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