【问题标题】:TypeError: WebDriver.__init__() got an unexpected keyword argument 'firefox_options' error using firefox_options as arguments in Selenium PythonTypeError:WebDriver.__init__() 在 Selenium Python 中使用 firefox_options 作为参数时遇到了意外的关键字参数“firefox_options”错误
【发布时间】:2022-01-16 09:56:58
【问题描述】:

我正在尝试创建一个从网站下载文件的脚本,为此我想更改下载文件路径。当我尝试使用 Firefox 选项执行此操作时,它给了我这个错误:

TypeError: WebDriver.__init__() got an unexpected keyword argument 'firefox_options'

代码:

from selenium import webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
import time

options = Options()

options.add_argument("download.default_directory=C:\\Music")
browser = webdriver.Firefox(firefox_options=options, executable_path=r'C:\\selenium\\geckodriver.exe')
browser.get('https://duckduckgo.com/')

【问题讨论】:

标签: python selenium selenium-webdriver firefox geckodriver


【解决方案1】:

浏览器选项参数firefox_options 在Selenium 3.8.0 中已弃用

  • 浏览器选项参数现在跨驱动程序标准化为options。 firefox_options、chrome_options 和 ie_options 现已弃用

您必须使用options,如下所示:

from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument("download.default_directory=C:\\Music")
browser = webdriver.Firefox(options=options, executable_path=r'C:\\selenium\\geckodriver.exe')

【讨论】:

  • 感谢它现在可以使用
猜你喜欢
  • 2020-03-08
  • 1970-01-01
  • 2015-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-08
  • 2015-04-14
  • 2019-01-13
相关资源
最近更新 更多