1

I am writing a script using Selenium to export an XML backup from the export page of a MediaWiki-based website.

I wish to download the XML file to a directory, bypassing the popup window that usually asks me what to do with the file.

When I look at the Network tab when downloading the .xml, file I see (under Response Headers) that content-type is application/xml; charset=utf-8.

Screenshot from Network tab on Firefox

After reading some answers here, as well as this reddit post, I am using:

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.preferences.instantApply",True)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain, application/octet-stream, text/xml, application/xml")
fp.set_preference("browser.helperApps.alwaysAsk.force",False)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.folderList",2)
    
driver = webdriver.Firefox(firefox_profile=fp, executable_path=r'C:\Python37\geckodriver.exe')
(...)
download_button.click()

However, the window still pops up and the file is not downloaded anywhere.

I made sure to update Selenium and the geckodriver.

What am I doing wrong?

Thank you!

2 Answers 2

1

After much trial-and-error for me this worked (it's Java but should be transferable to Python):

profile.setPreference("browser.download.viewableInternally.previousHandler.alwaysAskBeforeHandling.xml", false);
profile.setPreference("browser.download.viewableInternally.previousHandler.preferredAction.xml", 0);
profile.setPreference("browser.download.viewableInternally.typeWasRegistered.xml", true);
Sign up to request clarification or add additional context in comments.

Comments

0

I think you should pass a tuple as an argument, like this:

fp.set_preference('browser.helperApps.neverAsk.saveToDisk', (text/plain, application/octet-stream, text/xml, application/xml))

It works for me. PS: Ignore my poor english, I'm brazilian.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.