0

I am using python selenium and would like to download a pdf file, however it opens in my browser? How can I download it from my browser? Any way to click the following image, enter image description here

Before, all i had to do was disable the firefox download box dialog, but now I am not able to request the download. Any ideas? What should i do to request the download? I am also not able to find the file on the server.

profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "application/vnd.csv")

3 Answers3

0

There is no way do do it with selenium in a way you described. However you can tweak your browser, so it doesn't open pdf's but downloads them - and that can be done with selenium. Here's (How to auto save files using custom Firefox profile )a good example how to do it.

root
  • 76,608
  • 25
  • 108
  • 120
  • I have already tried that. It doesnt download just opens it in a pdf viewer in the browser. –  Oct 08 '12 at 16:34
  • as we can't see the webpage nor your code, it is hard to say why doesn't it work for you...if nothing else, use requests. – root Oct 08 '12 at 16:41
  • What about a context click, because it downloads if you do context click> save link as..., i can make a context click but do not know how to select the `save link as` option,code: `download_element = driver.find_element_by_link_text(download) ActionChains(driver).context_click(download_element).perform() ActionChains.click('link=Save Link As...')` –  Oct 08 '12 at 16:45
0

With AppLoader you can click on any button, icon, or shortcut, just like a real user.

0

Add

profile.set_preference("pdfjs.disabled",True)

That will disable the default pdf viewer in firefox.

Also your save-to-disk preference seems incorrect. It should be profile.set_preference("browser.helperApps.neverAsk.saveToDisk","application/pdf")

The last thing to keep in mind is that if you have multiple file types to download, you need to put them all under the same set_preference saveToDisk statement, comma separated, otherwise the later statement will overwrite the earlier settings.