TypeError: WebDriver.__init__() got an unexpected keyword argument 'firefox_options' error using firefox_options as arguments in Selenium Python

TypeError: WebDriver.__init__() got an unexpected keyword argument 'firefox_options' error using firefox_options as arguments in Selenium Python

我正在尝试创建一个从网站下载文件的脚本,为此我想更改下载文件路径。当我尝试使用 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/')

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

中弃用
  • Browser option parameters are now standardized across drivers as options. firefox_options, chrome_options, and ie_options are now deprecated

您必须使用 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')