Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

firefox - Selenium JS set_preference

I need to have selenium automation download a file using firefox. The automation successfully clicks the download, but a MIME opens to ask what to do. I need selenium to ignore this and just download the file.

Everything I have read days I should be able to use a function like this

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

But when I run this, it fails before it ever gets to clicking the download because this piece throws an error.

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

what am I doing wrong??

ALL answers listed on SO show this exact code snippet and it is not working.

question from:https://stackoverflow.com/questions/66052803/selenium-js-set-preference

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
const firefoxOption = new firefox.Options().setPreference(
 'browser.helperApps.neverAsk.saveToDisk',
 'application/zip,text/csv,text/txt',
);

That method is for python

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...