python - 给定路径上没有 chrome 二进制文件 - MacOS - Selenium - Python

标签 python macos selenium selenium-webdriver selenium-chromedriver

我刚刚开始使用带有 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 包含在项目文件夹本身中
enter image description here
/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

最佳答案

这解决了问题

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

关于python - 给定路径上没有 chrome 二进制文件 - MacOS - Selenium - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63047555/

相关文章:

python - 如何子类化 scipy.stats.norm ?

java - 对象未使用 PageFactory.initElements(driver,class); 进行初始化

macos - 像 OS X 中的 Xcode 一样的对话框

c++ - 当 C++11 应用程序使用非 C++11 库时返回值损坏

macos - 我想使用 graphviz,但错误 'syntax error in line 1 near ' {''

python - Python 中的 Selenium : Breaking a While Loop After an Onclick Attribute Changes

javascript - 使用 Selenium 测试 jQuery 元素数据()?

python - Pandas - 对具有相同名称开头的列求和

python - jinja2.exceptions.TemplateNotFound 错误

Python如何找出一个文本文件中的唯一元素并输出到另一个文本文件中