python - WebDriverException : Message: unknown error: no chrome binary at C:/. ../Chrome/Application/chrome.exe 与 ChromeDriver Selenium 和 Python

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

这里有点像 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,完全没有问题。

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

最佳答案

这个错误信息...

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.0chrome_options现在已弃用。您需要使用 options 虽然chrome_options 仍然有效。
  • key executable_path必须由 Value 支持,如下所示:
    • r'C:\python\chromedriver.exe'
    • "C:/python/chromedriver.exe"
    • "C:\\python\\chromedriver.exe"

关于python - WebDriverException : Message: unknown error: no chrome binary at C:/. ../Chrome/Application/chrome.exe 与 ChromeDriver Selenium 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53131669/

相关文章:

python - 如何在 sublime text 2 中配置 python 解释器以使其充当 IDLE python shell

python - try-except block 中的 Numpy 零除,引发 "RuntimeWarning: invalid value encountered in double_scalars"和奇怪的结果

python - 在python中获取模拟方法的参数

javascript - 我的 XML 文件未通过 Google Chrome 和 Internet Explorer

docker - 如何在 Dockerfile 中安装特定版本的 Chrome?

python - 将随机变量传递给 agg 函数 python

java - org.openqa.selenium.WebDriverException : Session [xyz] was terminated due to ORPHAN error using Zalenium

python - time.sleep 给出了所需的抓取但等到没有

selenium - 从匹配节点列表中选择第 n 个匹配节点

google-chrome - 如何绕过 Chrome 发送的 "Content-encoding gzip deflate" header ?