Web驱动程序异常:未知错误:在旧版本的Google Chrome中,无法在Python中找到带有Selenium的Chrome二进制错误

bnl4lu3b  于 2023-02-27  发布在  Go
关注(0)|答案(8)|浏览(130)

出于兼容性的原因,我更喜欢使用Chrome版本55.0.2883.75和Chrome驱动程序2.26。我从https://www.slimjet.com/chrome/google-chrome-old-version.php下载了旧版本的Chrome,从https://chromedriver.storage.googleapis.com/index.html?path=2.26/下载了Chrome驱动程序2.26。
我正在使用以下代码尝试设置我的Chrome二进制位置:

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

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome('chromedriver.exe', chrome_options = options)

然而,当我试图启动WebDriver时,Python返回以下错误:

WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.26.436362
(5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)

我试过搜索类似的问题和答案,但到目前为止还没有任何运气。任何帮助都非常感谢-提前感谢!

9rygscc1

9rygscc11#

此错误消息...

WebDriverException: unknown error: cannot find Chrome binary

...表示ChromeDriver无法在系统的默认位置找到Chrome二进制文件。
根据Chrome驱动程序-要求
服务器希望您将Chrome安装在每个系统的默认位置:
| 操作系统| chrome 的预期位置|
| - ------|- ------|
| Linux操作系统|/usr/文件夹/谷歌浏览器|
| 麦克|/应用程序/谷歌\Chrome浏览器应用程序/内容/MacOS/谷歌\Chrome浏览器|
| windows XP|% HOMEPATH %\本地设置\应用程序数据\Google\Chrome\应用程序\chrome.exe|
| Windows Vista及更新版本|C:\用户%用户名%\应用数据\本地\Google\Chrome浏览器\应用程序\chrome.exe|
1对于Linux系统,ChromeDriver预期/usr/bin/google-chrome是实际 * Chrome二进制文件 * 的 * 符号链接 *。

在非标准位置使用Chrome可执行文件

但是,您也可以覆盖默认的 * Chrome二进制位置 *,如下所示:
要使用通过 * ChromeDriver v2.26 * 安装在非标准位置的 * Chrome版本55.x *,您可以使用以下代码:

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

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()

相关文件

参考

您可以在以下位置找到详细讨论:

  • 使用Selenium时需要安装Chrome还是只安装chromedriver?
htrmnn0y

htrmnn0y2#

发生在我身上的事情是我没有安装chrome,主浏览器,下载浏览器,它修复了这个问题。

hmae6n7t

hmae6n7t3#

在本地使用旧版本的Chrome驱动程序与最新的Google Chrome一起给了我同样的例外。
只需转到ChromeDriver page,确保您有最新版本。

5lhxktic

5lhxktic4#

我在MacOS中也遇到过类似的问题,即使在chromeoptions中设置了二进制路径,它也不起作用。安装npm i chromedriver后得到了修复

icomxhvb

icomxhvb5#

从实际网站下载Chrome也很重要。我遇到了同样的问题,但我是从Ubuntu软件包管理器下载Chrome的。我卸载了包管理器版本,然后从网站安装,错误解决了。从其他包管理器安装可能会出现同样的问题。

fdbelqdn

fdbelqdn6#

检查https://sites.google.com/a/chromium.org/chromedriver/getting-started您可以在webdriver的构造函数中指定二进制路径:

driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.
wz1wpwve

wz1wpwve7#

我这样做是为了解决我的问题

private WebDriver driver;

@Before
public void StartBrowser() {

System.setProperty("webdriver.chrome.driver", "C://opt//WebDriver//bin//chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");}
z2acfund

z2acfund8#

我已经解决了这个问题,通过安装谷歌Chrome link和它解决了问题自动(我使用Kali Linux),并确保它安装到“/usr/bin”(默认下载到这里)。

相关问题