我正在使用 selenium pyhthon 尝试在 google chrome 中打开 amazon.com,但在运行代码时我不断收到此错误消息。
<块引用>selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件
我试图在 stackoverflow 上搜索这个错误,但我能找到的只有 Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac,我无法理解。我使用的是 mac M1,我有 chrome 版本 92.0.4515.107。我的代码是
from selenium import webdriver
chrome_driver_path = "/Users/asznee/selenium/chromedriver"
driver = webdriver.Chrome(chrome_driver_path)
driver.get("https://www.amazon.com")
答案 0 :(得分:0)
看看你的谷歌浏览器没有安装在默认位置
C:\Program Files\Google\Chrome\Application
已安装:
C:\Users\asznee\Desktop\Downloads\Google Chrome\Application
对吗?
所以为了解决这个问题,你的 chromdriver.exe 需要知道谷歌浏览器的安装位置:-
你可以试试下面的代码:-
options = webdriver.ChromeOptions()
options.binary_location = "/Users/asznee/Desktop/Downloads/Google Chrome/Application/chrome"
chrome_driver_binary = "/Users/asznee/selenium/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary, options = options)
答案 1 :(得分:0)
无需指定chrome驱动程序的路径,只需将chrome驱动程序保留在项目中即可 只需复制并粘贴到项目中
并开始初始化网络驱动程序 只需开始打字 WebDriver 驱动程序 = new ChromeDriver(); 并输入应用程序的 URL 并按照代码
答案 2 :(得分:0)
WebDriver 驱动程序 = new ChromeDriver();
WebDriver 有未实现的方法
这里是 chrome 驱动程序正在实现这些未实现的方法
chrome 驱动程序只是您告诉 selenium 在 chrome 浏览器上运行测试的驱动程序。 你可以下载它
https://chromedriver.chromium.org/home
如果您想使用 Firefox 浏览器,请使用 Gecko 驱动程序。