【问题标题】:Firefox Python selenium not going headlessFirefox Python selenium 不会无头
【发布时间】:2019-06-22 17:20:39
【问题描述】:

我正在尝试使 firefox 无头并完全按照文档中的说明进行操作。

这不应该做它应该做的事 即使我添加了无头参数,Firefox 窗口也会出现

cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False

options = webdriver.FirefoxOptions()
options.add_argument('-headless')
driver = webdriver.Firefox(firefox_options=options, capabilities=cap)

这不应该打开firefox窗口,但它会打开窗口 chrome和chromedriver我从来没有遇到过这种问题

我已经下载了 64 位 geckodriver 二进制文件,它在 PATH 中 我在这里做错了什么?

【问题讨论】:

    标签: python selenium firefox geckodriver selenium-firefoxdriver


    【解决方案1】:

    试试下面的代码块:

    from selenium.webdriver.firefox.options import Options
    
    options = Options()
    options.headless = True
    

    【讨论】:

    • 这看起来应该可以工作......我总是使用:add_argument('--headless') 不是options.headless = True,但很好的答案! +1
    • 谢谢@MosheSlavin 我会记住以上建议。
    【解决方案2】:

    您需要使用Options() 而不是webdriver.FirefoxOptions()

    from selenium.webdriver.firefox.options import Options
    
    options = Options()
    options.add_argument('--headless')
    

    希望对您有所帮助!

    【讨论】:

    • 还是一样,可能是geckodriver或者Firefox的bug
    • 还是同样的问题
    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2019-09-05
    • 2018-06-23
    • 2018-06-27
    相关资源
    最近更新 更多