简体   繁体   English

WebDriverException:消息:服务 /usr/bin/google-chrome 意外退出。 状态代码是:-11 使用 ChromeDriver Chrome 通过 Selenium Python

[英]WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: -11 with ChromeDriver Chrome through Selenium Python

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 脚本中运行 webdriver,当脚本尝试运行 google chrome 时,它​​以状态代码 11 退出。

Here is the python script:这是python脚本:

#!/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()

Here is the full output:这是完整的输出:

[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

Does anyone know why my script reports the error code 11 when trying to run google chrome?有谁知道为什么我的脚本在尝试运行谷歌浏览器时报告错误代码 11?

This error message...这个错误信息...

selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: -11

...implies that the ChromeDriver was unable to initiate/spawn the new Browsing Context ie Chrome Browser session properly. ...暗示ChromeDriver无法正确启动/生成新的浏览上下文,Chrome 浏览器会话。

Seems you were almost there.看来你快到了。 The default argument for webdriver.Chrome() is the absolute path of the ChromeDriver binary. webdriver.Chrome()的默认参数是ChromeDriver二进制文件的绝对路径 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

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:此外,如果您需要通过Chrome浏览器绝对路径二进制,你必须使用binary_location通过实例属性chrome.options如下:

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:您可以在以下位置找到详细讨论:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium.common.exceptions.WebDriverException:消息:Linux 上的 ChromeDriver Selenium Python 服务 /usr/bin/google-chrome 意外退出 - selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited with ChromeDriver Selenium Python on Linux WebDriverException:消息:服务 /content/chromedriver 意外退出。 状态代码为:-6 使用 ChromeDriver Google Colab 和 Selenium - WebDriverException: Message: Service /content/chromedriver unexpectedly exited. Status code was: -6 with ChromeDriver Google Colab and Selenium WebDriverException:服务 U:/Scraping/chromedriver.exe 意外退出。 状态代码为:1 使用 Chrome 和 Python 时 - WebDriverException: Service U:/Scraping/chromedriver.exe unexpectedly exited. Status code was: 1 while working with Chrome and Python WebDriverException:消息:服务 chromedriver 意外退出。 状态代码为:127 - WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 WebDriverException:消息:服务 chromedriver 意外退出。 状态代码为:127,在 Ubuntu 中使用 ChromeDriver 和 Selenium - WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 with ChromeDriver and Selenium in Ubuntu Docker Selenium:selenium.common.exceptions.WebDriverException:消息:服务chromedriver意外退出。 状态码为:127 - Docker Selenium: selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 selenium.common.exceptions.WebDriverException:消息:服务 chromedriver 意外退出。 状态码是:1 - selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1 selenium.common.exceptions.WebDriverException:消息:服务geckodriver意外退出。 状态代码为:-11-如何解决? - selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: -11 - How to fix? selenium.common.exceptions.WebDriverException:消息:chromedriver 意外退出。 状态码为:255 使用 Dockerfile 时 - selenium.common.exceptions.WebDriverException: Message: chromedriver unexpectedly exited. Status code was: 255 When using Dockerfile webDriverException“selenium.common.exceptions.WebDriverException:消息:Service./webdrivers/geckodriver 意外退出。状态代码为:1” - webDriverException "selenium.common.exceptions.WebDriverException: Message: Service ./webdrivers/geckodriver unexpectedly exited. Status code was: 1"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM