[英]Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
[英]chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed error using Selenium through Python
在我开始之前:我知道有十亿个关于 Selenium 不起作用的帖子,以及各种尝试的解决方案。 我相信我已经尝试了一切,但如果我遗漏了什么,请原谅我。 我的头撞在墙上,希望得到帮助。
以下是我采取的一些步骤:
我下载了 selenium(Ubuntu,Python)的 chromedriver,并使用chmod 755
和chmod 777
使驱动程序可执行。 之后,我用 ./chromedriver 启动了./chromedriver
。
我尝试了 Selenium 的各种选项,包括手动添加运行 chromedriver 的端口
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/home/myname/projects/myproject/chromedriver"
options.add_argument("--remote-debugging-port=9515")
chrome_driver_binary = '/home/myname/projects/myproject/chromedriver'
driver = webdriver.Chrome(chrome_driver_binary, options = options)
driver.get('http://www.ubuntu.com/')
我已经尝试过其他帖子中建议的选项,例如:
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-setuid-sandbox")
我确保我使用的是与我的 Chrome 版本兼容的 chromedriver。
似乎没有任何效果。 我不断收到此错误:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(chrome not reachable)
(The process started from chrome location /home/myname/projects/myproject/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
我真诚地感谢别人对这个问题的解释。
您需要注意以下几点:
options.binary_location
:指的是google-chrome二进制位置,如果Google Chrome未安装在默认位置,则使用该位置。 请参阅: WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 Selenium 的 Chrome 二进制错误
--remote-debugging-port
:如果您不是远程调试,则可以安全地删除此参数。
chrome_driver_binary
:指ChromeDriver在系统中的绝对位置。
webdriver.Chrome(chrome_driver_binary, options = options)
:此外,您可能希望添加key executable_path ,如下所示:
chrome_driver_binary = '/home/myname/projects/myproject/chromedriver' driver = webdriver.Chrome(executable_path=chrome_driver_binary, options = options) driver.get('http://www.ubuntu.com/')
--no-sandbox
、 --headless
、 --disable-dev-shm-usage
、 --disable-setuid-sandbox
等是您可能不需要启动的可选设置。
启动Selenium驱动的ChromeDriver启动的 google-chrome浏览上下文的最小代码块可以是:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(executable_path='/home/myname/projects/myproject/chromedriver', options=options)
driver.get("http://www.ubuntu.com/")
您可以在以下位置找到一些相关的详细讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.