RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox

RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox

有人...在 Firefox 中使用 Selenium。写入:

真烦人!我有 Firefox 版本 58.0.2、geckodriver 0.19.1、selenium 3.9.0、python 3.6.4,但它不起作用!错误。

我安装 Firefox 时没有使用 sudo apt-get(解压缩的存档),因为存储库中没有新版本的 Firefox。

所以问题是 selenium 找不到 Firefox,因为它的路径不在您的 $PATH 变量上。

要解决问题,您有两个选择:

  1. 使用包管理器从存储库安装 Firefox

  2. 将安装的 Firefox 二进制文件指定为 selenium。

  3. 将 Firefox 二进制文件添加到 Path 变量。

对于第二个选项:

要设置 Firefox 的自定义路径,您需要使用 FirefoxBinary:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('/Firefox/Path')
driver = webdriver.Firefox(firefox_binary=binary)

对于第三个选项:

将以下内容添加到您的 ~/.profile 或 ~/.bashrc:

export PATH="$PATH:/home/firefox"

使用 which firefoxwhereis firefox 获取 Firefox 路径。