Selenium:WebDriverException:Chrome无法启动:由于google-chrome不再运行而崩溃,因此ChromeDriver假设Chrome已崩溃

问题描述 投票:13回答:7

我知道这个问题有几个答案,但到目前为止我没有任何帮助,所以我发布了一个新问题。

最近我换了电脑,从那时起我不能用硒发射铬。我也试过firefox但浏览器只是没有lanch。

from selenium import webdriver

d = webdriver.Chrome('/home/PycharmProjects/chromedriver')

d.get('https://www.google.nl/')

我收到以下错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)

我安装了最新的chrome版本和chromedriver

编辑:尝试@ b0sss解决方案后,我收到以下错误。

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)
python selenium google-chrome selenium-webdriver selenium-chromedriver
7个回答
19
投票

尝试下载HERE并使用最新的Chrome驱动程序版本。

https://sites.google.com/a/chromium.org/chromedriver/downloads

编辑:

试试这个:

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/PycharmProjects/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')

9
投票

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

...暗示ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。

您的主要问题是Chrome浏览器未安装在系统的默认位置。

服务器即ChromeDriver希望您将Chrome安装在每个系统的默认位置,如下图所示:

1对于Linux系统,ChromeDriver希望/usr/bin/google-chrome成为实际Chrome二进制文件的符号链接。


如果您在非标准位置使用Chrome可执行文件,则必须覆盖Chrome二进制位置。如下:

  • Python解决方案: from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "C:\\path\\to\\chrome.exe" driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe') driver.get('http://google.com/') print("Chrome Browser Invoked") driver.quit()
  • Java解决方案:


5
投票

我遇到了类似的问题,并发现选项参数必须按特定顺序排列。我只知道在我的Ubuntu 18机器上运行所需的两个参数。这个示例代码在我的最后工作:

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

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')

4
投票

我遇到了在docker容器上运行的确切问题(在构建环境中)。在ssh进入容器后,我尝试手动运行测试并仍然遇到

(unknown error: DevToolsActivePort file doesn't exist)
     (The process started from chrome location /usr/bin/google-chrome-stable is 
      no longer running, so ChromeDriver is assuming that Chrome has crashed.)

当我尝试在本地运行chrome /usr/bin/google-chrome-stable时,出现错误信息

Running as root without --no-sandbox is not supported

我检查了我的ChromeOptions并且它缺少--no-sandbox,这就是它无法生成chrome的原因。

capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
  chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)

4
投票

在我的情况下,错误是与www-data用户,但不是正常用户在开发。该错误是为该用户初始化x显示的问题。因此,问题解决了运行我的selenium测试而没有打开浏览器窗口,无头:

opts.set_headless(True)

3
投票

希望这有助于某人。这在Ubuntu 18.10上对我有用

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()

2
投票

假设您已经下载了chromeDriver,则在打开多个chrome选项卡时也会发生此错误。

如果关闭所有选项卡并再次运行,则应清除错误。

© www.soinside.com 2019 - 2024. All rights reserved.