【问题标题】:AttributeError: 'Options' object has no attribute 'binary' error invoking Headless Firefox using GeckoDriver through SeleniumAttributeError: 'Options' object has no attribute 'binary' 使用 GeckoDriver 通过 Selenium 调用 Headless Firefox 错误
【发布时间】:2021-03-25 06:25:31
【问题描述】:
options = FirefoxOptions()
options.add_argument("--headless")


driver = webdriver.Firefox(firefox_options=options, executable_path='/Users/toprak/Desktop/geckodriver') 
driver.get("https://twitter.com/login?lang=en")

当我尝试运行我的代码时,我收到了这个错误:

Warning (from warnings module):
  File "/Users/toprak/Desktop/topla.py", line 19
    driver = webdriver.Firefox(firefox_options=options, executable_path='/Users/toprak/Desktop/geckodriver')
DeprecationWarning: use options instead of firefox_options
Traceback (most recent call last):
  File "/Users/toprak/Desktop/topla.py", line 19, in <module>
    driver = webdriver.Firefox(firefox_options=options, executable_path='/Users/toprak/Desktop/geckodriver')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 137, in __init__
    if options.binary is not None:
AttributeError: 'Options' object has no attribute 'binary'

当我删除关于选项的行并取出“firefox_options=options”时,代码可以正常工作。我应该怎么做才能解决这个问题?

【问题讨论】:

标签: python selenium selenium-webdriver geckodriver firefox-headless


【解决方案1】:

您需要使用options 对象,而不是使用firefox_options 对象。此外,您需要使用 headless 属性。所以你的有效代码块将是:

options = FirefoxOptions()
options.headless = True

driver = webdriver.Firefox(executable_path='/Users/toprak/Desktop/geckodriver', options=options) 
driver.get("https://twitter.com/login?lang=en")

参考文献

您可以在以下位置找到一些相关的详细讨论:

【讨论】:

  • 仍然给出相同的“attributeError: 'Options' object has no attribute 'binary'”错误
  • @Xia 查看更新的答案并让我知道状态
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-01
  • 2019-10-17
  • 2022-12-03
  • 2018-11-03
  • 1970-01-01
  • 2014-12-20
  • 2021-11-08
相关资源
最近更新 更多