簡體   English   中英

selenium.common.exceptions.WebDriverException:消息:未知錯誤:在ubuntu上執行selenium python腳本時,chrome無法啟動

[英]selenium.common.exceptions.WebDriverException: Message: unknown error: chrome failed to start while executing selenium python script on ubuntu

我在ubuntu上運行python3腳本

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')  # Last I checked this was necessary.
driver = webdriver.Chrome("/home/admin/web/web.com/public_html/scripts/az/chromedriver", chrome_options=options)

作為普通用戶運行,我收到以下錯誤:

$ python3 getStock.py
Traceback (most recent call last):
File "getStock.py", line 61, in <module>
    driver = webdriver.Chrome("/home/admin/web/web.com/public_html/scripts/az/chromedriver", chrome_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: chrome failed to start
(Driver info: chromedriver=2.38.551591 (bcc4a2cdef0f6b942b2bb8049068f65340fa2a69),platform=Linux 4.2.0-042stab120.16 x86_64)

嘗試使用sudo; 我仍然得到以下錯誤

$ sudo python3 getStock.py
[sudo] password for admin:
Traceback (most recent call last):
File "getStock.py", line 61, in <module>
    driver = webdriver.Chrome("/home/admin/web/web.com/public_html/scripts/az/chromedriver", chrome_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.38.551591 (bcc4a2cdef0f6b942b2bb8049068f65340fa2a69),platform=Linux 4.2.0-042stab120.16 x86_64)

不知道發生了什么事? 我試過跟隨;

  1. 我試過更新硒;
  2. 我試過運行python 2.x和python 3.x.
  3. 我嘗試以普通用戶和sudo用戶身份運行腳本
  4. 我已經嘗試將權限更改為甚至chmod 777

這是我的版本:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

Python 3.5.2
Requirement already satisfied: selenium in /usr/local/lib/python3.5/dist-packages (3.11.0)

此錯誤消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: chrome failed to start

...表示您的WebClient Chrome無法啟動。

您需要通過單個正斜杠傳遞Key executable_path以及引用ChromeDriver絕對路徑的 ,即\\以及原始ie r開關,如下所示:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
#options.add_argument('--disable-gpu')  # applicable to windows os only
driver = webdriver.Chrome(chrome_options=options, executable_path=r'/home/admin/web/web.com/public_html/scripts/az/chromedriver')

附加步驟

  • 通過IDE 清理 項目工作區 ,並僅使用所需的依賴項重建項目。
  • 使用CCleaner工具在執行Test Suite之前和之后擦除所有操作系統。
  • 如果您的基本Web客戶端版本太舊,請通過Revo Uninstaller將其卸載並安裝最新的GA和已發布的Web客戶端版本。
  • 進行系統重啟
  • 執行你的@Test

真正的錯誤是unknown error: Chrome failed to start: exited abnormally

chromedriver=2.38.551591 ,你使用的是chromedriver=2.38.551591

只需確保您是否使用了與本地計算機上安裝的chrome瀏覽器相關的正確的chromedriver版本。

您的chromedriver版本適用於Chrome瀏覽器版本> 67.xx

您可以參考此頁面以獲取兼容性參考。

下面的代碼在同一環境中適用於我(但我的chromedriver版本是2.36):

options = Options()
options.add_experimental_option("detach", True)
options.add_argument("--window-position=0,0")
options.add_argument("--headless")
driver = webdriver.Chrome("path", chrome_options=options)

檢查它是否適合你:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:在 Python 中使用 ChromeDriver 和 Selenium 崩潰 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome無法以Selenium和RaspberryPi上的Chrome啟動 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome無法啟動:使用ChromeDriver Chrome和Selenium異常退出 selenium.common.exceptions.WebDriverException:消息:未知錯誤:無法使用帶有Selenium Python的ChromeDriver Chrome創建Chrome進程 selenium.common.exceptions.WebDriverException:消息:未知錯誤:無法使用 ChromeDriver Chrome Selenium 創建 Chrome 進程錯誤 Selenium.common.exceptions.WebDriverException:消息:未知錯誤:沒有 chrome 二進制文件 selenium.common.exceptions.WebDriverException:消息:未知錯誤:通過Selenium Python使用execute_script()時,“腳本”必須是字符串 TDD-Django(部署)錯誤:selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome無法啟動:異常退出 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:異常退出。 Dockerize Flask 應用程序 Python(Selenium):selenium.common.exceptions.WebDriverException:消息:處理指定命令時發生未知錯誤
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM