from selenium import webdriver
driver = webdriver.Chrome(executable_path="/usr/bin/google-chrome")
driver.get('https://python.org')

在python中执行上面的代码时,chrome浏览器打开了,但没有重定向到https://python.org . 2或3秒后,chrome将自动关闭并产生错误:

回溯(最近一次调用最后一次):文件“test.py”,第4行,在driver = webdriver.Chrome(executable_path =“/ snap / bin / chromium”)文件“/home/ShihaD/.local/lib/python2 .7 / site-packages / selenium / webdriver / chrome / webdriver.py“,第68行,在init self.service.start()文件”/home/ShihaD/.local/lib/python2.7/site-packages/ selenium / webdriver / common / service.py“,第104行,在启动时引发WebDriverException(”无法连接到服务%s“%self.path)selenium.common.exceptions.WebDriverException:消息:无法连接到服务/卡/斌/铬

我已经尝试过解决方案Running Selenium WebDriver python bindings in chrome . 但不工作 .

版本:Python 2.7.15 Google Chrome 67.0.3396.99 ChromeDriver 2.40

已经检查了/ etc / hosts和127.0.0.1 localhost .