【问题标题】:WebDriverException: Message: unknown error: no chrome binary at C:/.../Chrome/Application/chrome.exe with ChromeDriver Selenium and PythonWebDriverException:消息:未知错误:C:/.../Chrome/Application/chrome.exe 中没有带有 ChromeDriver Selenium 和 Python 的 chrome 二进制文件
【发布时间】:2018-11-03 13:11:36
【问题描述】:

这里有点 Python 新手...

Windows 7 x64 和 Python 3.7

我已经安装了 Selenium 和 Chrome Webdriver。我正在使用:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe')
driver.get('http://google.com/')

我明白了:

\python\python.exe C:/py/defectURLS/app.py
C:/py/defectURLS/app.py:6: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe')
Traceback (most recent call last):
  File "C:/py/defectURLS/app.py", line 6, in <module>
    driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe')
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at C:/Program Files (x86)/Google/Chrome/Application/chrome.exe
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64)

现在,我很确定确凿证据是:

 selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at C:/Program Files (x86)/Google/Chrome/Application/chrome.exe
      (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64)

这表明 Selenium 可以找到 webdriver 正常,因为它能够报告 webdriver 版本。该错误似乎表明 chrome 二进制文件未位于给定位置。但我完全确定这是 Chrome.exe 所在的位置。我可以直接从该路径启动 chrome.exe,完全没有问题。

非常感谢指导可能出现的问题。

【问题讨论】:

  • 尝试传递 options 而不是 chrome_options

标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


【解决方案1】:

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally

...暗示 ChromeDriver 无法找到 chrome 二进制文件 chrome.exe

您需要考虑以下几个事实:

  • 您可能正在使用 Selenium Python Client v3.14.1Selenium Python Client v3.141.0,而 chrome_options 现在已弃用。您需要使用 options 虽然 chrome_options 仍然有效。
  • Key executable_path 必须支持以下任一Value
    • r'C:\python\chromedriver.exe'
    • "C:/python/chromedriver.exe"
    • "C:\\python\\chromedriver.exe"

【讨论】:

  • 有三个问题,每个问题在您的回复后变得更加清晰。 1. 我的 Chrome 二进制文件路径实际上不正确。在我的受限桌面上打包 Chrome 的方式包含几个 chrome.exe 实例,而我指向的地方不是一个干净的二进制文件。 2. 我需要更改为使用“选项”而不是 chrome_options。除此之外,我还需要其他几个参数。 3. 我使用的 webdriver 版本想与 Chrome 69 交互,而我安装了 Chrome 65。非常感谢!
猜你喜欢
  • 2021-07-18
  • 1970-01-01
  • 2018-10-12
  • 2021-04-02
  • 2017-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多