【问题标题】:No chrome Binary at the given path - MacOS - Selenium - Python给定路径中没有 chrome 二进制文件 - MacOS - Selenium - Python
【发布时间】:2020-11-12 18:48:58
【问题描述】:

我刚开始使用带有 chromedrivers 的 selenium web 驱动程序。我正在使用 MacOS,当我尝试将 chrome 浏览器的路径设置为二进制路径时,我总是遇到同样的错误,即在给定的某某路径上没有 chrome 二进制文件。

import os  
from selenium import webdriver  
from selenium.webdriver.chrome.options import Options  
from selenium.webdriver.common.keys import Keys

chrome_options = Options()

chrome_options.binary_location = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"

driver = webdriver.Chrome(executable_path = os.path.abspath("drivers/chromedriver") , chrome_options = chrome_options)

chrome_options.binary_location 中的给定路径是正确的,这就是我找到我的 chrome 浏览器的地方。我还将我的 chromedriver 包含在项目文件夹本身中

/Applications/Codes/Selenium/seleniumproject/ChromeBinary.py:11: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(executable_path = os.path.abspath("drivers/chromedriver") , chrome_options = chrome_options)
Traceback (most recent call last):
  File "/Applications/Codes/Selenium/seleniumproject/ChromeBinary.py", line 11, in <module>
    driver = webdriver.Chrome(executable_path = os.path.abspath("drivers/chromedriver") , chrome_options = chrome_options)
  File "/Users/apple/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/Users/apple/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Users/apple/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Users/apple/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/apple/opt/anaconda3/lib/python3.7/site-packages/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 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

【问题讨论】:

    标签: python macos selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    这解决了问题

    chrome_options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    

    【讨论】:

    • 天才兄弟,记住不用'\'键来逃避空格的家伙
    【解决方案2】:

    提供的二进制路径'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'不是有效路径

    尝试使用 r'/Applications/Google/Chrome.app/Contents/MacOS/Google/Chrome' 代替。

    【讨论】:

      【解决方案3】:

      与问题无关。但是您可以避免使用为 chrome 驱动程序提供路径。

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      from webdriver_manager.chrome import ChromeDriverManager
      
      # chrome_options = Options()
      # chrome_options.add_argument("--headless")
      driver = webdriver.Chrome(ChromeDriverManager().install())#, chrome_options=chrome_options)
      driver.set_window_size(1024, 600)
      driver.maximize_window()
      

      webdriver_manager可以使用pip install webdriver_manager安装

      【讨论】:

        【解决方案4】:

        您的路径无效,您同时使用正斜杠和反斜杠

        【讨论】:

          猜你喜欢
          • 2019-02-24
          • 2020-10-18
          • 2016-09-19
          • 1970-01-01
          • 2020-09-25
          • 2022-07-16
          • 1970-01-01
          • 1970-01-01
          • 2012-07-15
          相关资源
          最近更新 更多