Selenium: WebDriverException: Chrome启动失败:因为Google Chrome不再运行,所以ChromeDriver认为Chrome已经崩溃。

115

最近我换了电脑,自那以后就无法使用selenium启动Chrome。我还尝试了Firefox,但浏览器实例就是无法启动。

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)
22个回答

0

我遇到了相同的问题,但是我通过将Chromedriver移动到此路径'/opt/google/chrome/'来解决它。

这段代码现在可以正常运行。

from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')

0

对我来说,根本问题在于google-chrome/chromedriver版本与Selenium版本不兼容。

Selenium和Chrome一直都很好用,直到几天前我开始遇到缺少DevToolsActivePort的问题。在尝试了thread上各种解决方案之后,我终于意识到Chrome版本可能与Selenium版本不兼容。 最初错误发生时的版本:

# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77

我随后将Chrome和ChromeDriver降级到109.0.5414.74,但仍然遇到了相同的错误。我在另一台机器上检查了版本,并发现这个组合可以工作:

# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16

然而,我无法找到谷歌浏览器V80的下载链接。这个评论中提供了V97的下载链接,因此我选择安装了该版本。可能会有更高版本的谷歌浏览器可以使用,但在修复了这么多天之后,我渴望转向其他事情。

sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable

wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin

之后,我的Selenium调用又可以正常工作了。最终版本组合:

# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接