简体   繁体   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

I am running following python3 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)

Running as normal user, I am getting following error: 作为普通用户运行,我收到以下错误:

$ 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)

Trying with sudo also; 尝试使用sudo; still I am getting following error 我仍然得到以下错误

$ 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)

Not sure what is going on? 不知道发生了什么事? I have tried following; 我试过跟随;

  1. I have tried updating selenium; 我试过更新硒;
  2. I have tried running as python 2.x and python 3.x 我试过运行python 2.x和python 3.x.
  3. I have tried running the script as a normal user and sudo user 我尝试以普通用户和sudo用户身份运行脚本
  4. I have tried changing the permissions to even chmod 777 我已经尝试将权限更改为甚至chmod 777

Here are my versions: 这是我的版本:

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)

This error message... 此错误消息...

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

...implies that your WebClient Chrome failed to start. ...表示您的WebClient Chrome无法启动。

Solution

You need to pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver through single forward slash ie \\ along with the raw ie r switch as follows : 您需要通过单个正斜杠传递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')

Additional Steps 附加步骤

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only. 通过IDE 清理 项目工作区 ,并仅使用所需的依赖项重建项目。
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite . 使用CCleaner工具在执行Test Suite之前和之后擦除所有操作系统。
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client . 如果您的基本Web客户端版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的Web客户端版本。
  • Take a System Reboot . 进行系统重启
  • Execute your @Test . 执行你的@Test

The real error is unknown error: Chrome failed to start: exited abnormally . 真正的错误是unknown error: Chrome failed to start: exited abnormally

Since , you are using chromedriver=2.38.551591 . chromedriver=2.38.551591 ,你使用的是chromedriver=2.38.551591

Just make sure whether you are using correct chromedriver version with respect to the chrome browser installed on your local machine. 只需确保您是否使用了与本地计算机上安装的chrome浏览器相关的正确的chromedriver版本。

Your version of chromedriver works with chrome browser versions > 67.xx 您的chromedriver版本适用于Chrome浏览器版本> 67.xx

You can refer this page for compatibility references. 您可以参考此页面以获取兼容性参考。

this code below is working for me on the same environment (but my chromedriver version is 2.36): 下面的代码在同一环境中适用于我(但我的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)

Check if it works for you :) 检查它是否适合你:)

暂无
暂无

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

相关问题 selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法以Selenium和RaspberryPi上的Chrome启动 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start with Selenium and Chrome on RaspberryPi selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:使用ChromeDriver Chrome和Selenium异常退出 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用带有Selenium Python的ChromeDriver Chrome创建Chrome进程 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 ChromeDriver Chrome Selenium 创建 Chrome 进程错误 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process error with ChromeDriver Chrome Selenium Selenium.common.exceptions.WebDriverException:消息:未知错误:没有 chrome 二进制文件 - Selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary selenium.common.exceptions.WebDriverException:消息:未知错误:通过Selenium Python使用execute_script()时,“脚本”必须是字符串 - selenium.common.exceptions.WebDriverException: Message: unknown error: 'script' must be a string while using execute_script() through Selenium Python TDD-Django(部署)错误:selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:异常退出 - TDD-Django(deploy) Error : selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:异常退出。 Dockerize Flask 应用程序 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. Dockerize Flask Application Python(Selenium):selenium.common.exceptions.WebDriverException:消息:处理指定命令时发生未知错误 - Python (Selenium): selenium.common.exceptions.WebDriverException: Message: An unknown error occurred while processing the specified command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM