Skip to main content
 首页 » 编程设计

python之WebDriverException : Message: Expected browser binary location, 但无法在默认位置找到二进制文件

2025年01月19日40小虾米

我尝试在 Python 2.7 中使用 Selenium,但出现以下错误,

WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

知道它会是什么吗?

请您参考如下方法:

您可以通过两种不同的方式避免此问题:

  1. 明确在哪里可以找到您的 selenium 代码的 firefox 二进制文件:

    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 
    from selenium import webdriver 
    firefox_binary = FirefoxBinary('/usr/bin/firefox/') 
    driver = webdriver.Firefox(firefox_binary=firefox_binary) 
    
  2. 将 firefox 添加到您的 PATH 环境变量中。 Windows , Ubuntu