【问题标题】:selenium - Can't work out how to get FireFox WebDriver to workselenium - 无法弄清楚如何让 FireFox WebDriver 工作
【发布时间】:2018-04-05 02:13:12
【问题描述】:

这应该很容易,但我错过了一些东西。我只是想让一些 selenium python 测试在 firefox 上运行,它们在 chrome 中完美运行。

问题只是试图让 ff webdriver 启动并运行!

我有以下代码,所有路径都是正确的:

import selenium
from selenium.webdriver.firefox import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
profile = webdriver.FirefoxProfile()
geckopath = 'C:\source\web_deploy_tests\geckodriver.exe'
browser = selenium.webdriver.Firefox(
    capabilities={},
    executable_path=geckopath,
    firefox_profile=profile,
    firefox_binary=binary
)
browser.get("http://google.com")

我正在使用 Python 3.6.2、selenium 3.6.0 并拥有 geckodriver.exe 的 v0.19.0 和 FF 是 v56.0.1。

当我运行上面的代码时,firefox 出现了,但只是在那里停留了大约 30 秒,然后崩溃:

selenium.common.exceptions.WebDriverException:消息:无法加载 轮廓。可能的 Firefox 版本不匹配。您必须使用 GeckoDriver 而不是 Firefox 48+。简介目录: C:\Users\ADMINI~1\AppData\Local\Temp\3\tmpkx5dau8h 如果您指定了 FirefoxBinary 构造函数中的 log_file,查看详细信息。

我尝试了各种 args 组合,但都失败了。

有什么想法吗? TIA

【问题讨论】:

    标签: python-3.x selenium firefox


    【解决方案1】:

    我通过传入 DesiredCapabilities.FIREFOX 让它工作

    import selenium
    from selenium.webdriver import DesiredCapabilities
    from selenium.webdriver.firefox import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
    profile = webdriver.FirefoxProfile()
    geckopath = 'C:\source\web_deploy_tests\geckodriver.exe'
    browser = selenium.webdriver.Firefox(
        capabilities=**DesiredCapabilities.FIREFOX**,
        executable_path=geckopath,
        firefox_profile=profile,
        firefox_binary=binary
    )
    browser.get("http://google.com")
    

    现在我至少可以调出浏览器窗口了!

    【讨论】:

    • 这是一个答案。为什么你认为通过它会起作用?弹出窗口后会发生什么?
    猜你喜欢
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多