WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: -11 with ChromeDriver Chrome through Selenium Python(WebDriverException:消息:服务/usr/bin/google-chrome 意外退出.状态代码是:-11 with ChromeDriver Chrome through Selenium
问题描述
我正在尝试在 Python 脚本中运行 webdriver,当脚本尝试运行 google chrome 时,它会以状态码 11 退出.
I am trying to run webdriver in a Python script, and when the script tries to run google chrome it exits with status code 11.
这里是python脚本:
Here is the python script:
#!/usr/bin/python3
import time
from selenium import webdriver
driver = webdriver.Chrome('/usr/bin/google-chrome') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
这是完整的输出:
[ec2-user@ip-xxx-xx-xx-xxx pythonscrape]$ python3 test-selenium-chrome.py
Traceback (most recent call last):
File "test-selenium-chrome.py", line 5, in <module>
driver = webdriver.Chrome('/usr/bin/google-chrome') # Optional argument, if not specified will search path.
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: -11
有谁知道为什么我的脚本在尝试运行 google chrome 时会报告错误代码 11?
Does anyone know why my script reports the error code 11 when trying to run google chrome?
推荐答案
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: -11
...暗示 ChromeDriver 无法正确启动/生成新的 Browsing Context 即 Chrome 浏览器 会话.
...implies that the ChromeDriver was unable to initiate/spawn the new Browsing Context i.e. Chrome Browser session properly.
看来你快到了.webdriver.Chrome()
的默认参数是 ChromeDriver 二进制文件的绝对路径.但是,根据最佳实践,您必须同时发送 Key 和 Value,如下所示:
Seems you were almost there. The default argument for webdriver.Chrome()
is the absolute path of the ChromeDriver binary. However, as per best practices you must send both the Key and the Value as follows:
driver = webdriver.Chrome(executable_path='/path/to/chromedriver') # Optional argument, if not specified will search path
此外,如果您需要传递 Chrome 二进制文件的绝对路径,您必须通过 chrome.options
如下:
Further, if you need to pass the absolute path of the Chrome binary you have to use the binary_location
property through an instance of chrome.options
as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(options=options, executable_path='/path/to/chromedriver')
driver.get('http://google.com/')
<小时>
参考
您可以在以下位置找到详细讨论:
Reference
You can find a detailed discussion in:
- Selenium: WebDriverException:Chrome启动失败:由于 google-chrome 不再运行而崩溃,因此 ChromeDriver 假设 Chrome 已崩溃
这篇关于WebDriverException:消息:服务/usr/bin/google-chrome 意外退出.状态代码是:-11 with ChromeDriver Chrome through Selenium Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WebDriverException:消息:服务/usr/bin/google-chrome 意外退出.状态代码是:-11 with ChromeDriver Chrome through Selenium Python
基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01