硒 set_preference

Selenium JS set_preference

我需要让 selenium 自动使用 firefox 下载文件。 自动化成功单击下载,但会打开一个 MIME 询问要做什么。我需要 selenium 来忽略它并只下载文件。

我读过的所有东西我应该能够使用这样的功能

const firefoxOption = new firefox.Options().set_preference(
 'browser.helperApps.neverAsk.saveToDisk',
 'application/zip,text/csv,text/txt',
);

但是当我 运行 这个时,它在点击下载之前就失败了,因为这件作品会引发错误。

TypeError: (intermediate value).set_preference is not a function

我做错了什么??

SO 上列出的所有答案都显示了这个确切的代码片段,但它不起作用。

const firefoxOption = new firefox.Options().setPreference(
 'browser.helperApps.neverAsk.saveToDisk',
 'application/zip,text/csv,text/txt',
);

该方法适用于python

https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/firefox_exports_Options.html