3

I am using this code to automate a flow which will download a Winzip file without prompt. But it does not seem to work

profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',("application/zip,
                                                   application/octet-stream"))
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.dir', '/home/jack/DOWNLOAD')
self.driver = webdriver.Firefox(firefox_profile=profile)

I still see the dialog box being opened while automation.

7
  • if you disable prompt manually on the first download, does it work correctly for the downloads after that? Commented Nov 29, 2012 at 7:08
  • @root No I am not able to do it manually as well. Also, browser.download.dir is not present in about:config Commented Nov 29, 2012 at 7:14
  • if you are on linux what does the following command give you curl -I https://www.downloadadress.com/ | grep Content-Type Commented Nov 29, 2012 at 7:22
  • Have you've tried application/x-zip-compressed and application/x-rar-compressed as MIME types as well? Commented Nov 29, 2012 at 7:29
  • @RocketDonkey Yes I tried them but in vein. Commented Nov 29, 2012 at 14:58

1 Answer 1

3

I solved this situation by extracting the href of the download link and using the python urllib module.

Using the below code, one can download the file and save it in a different file name as well.

import urllib
url = driver.find_element_by_link_text("Download").get_attribute("href");
urllib.urlretrieve(url, "saveasfilename") 
Sign up to request clarification or add additional context in comments.

1 Comment

@cppcoder can we provide the destination folder as well?

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.