簡體   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