0

download error

How to avoid this issue using selenium and python

  • 2
    Possible duplicate of [How to disable 'This type of file can harm your computer' pop up](https://stackoverflow.com/questions/34130774/how-to-disable-this-type-of-file-can-harm-your-computer-pop-up) – Anam Nizami Jun 27 '18 at 09:18
  • Hi @Ketan have you fixed this one ? can you provide if there is any solution ? – Firnaz Jun 25 '20 at 13:00

1 Answers1

0

You should set Selenium profile to enable downloading without asking:

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
profile.set_preference("browser.safebrowsing.enabled", 'false')
driver = webdriver.Firefox(profile)
driver.get("http://yourpage.com")

"application/octet-stream" is the file type, check MIME types if you don't know your file type

With chrome you should be able to use:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_experimental_option("prefs", {
  "download.default_directory": r"C:\Users\xxx\downloads\Test", # Insert the path where you want your files to be saved!
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": True
})
driver = webdriver.Chrome(chrome_options=chrome_options)

Check also this answer for some more informations

Gsk
  • 2,929
  • 5
  • 22
  • 29
  • This is with firefox can you give some solution with chrome browser? – Ketan Gupta Jun 27 '18 at 09:51
  • @KetanGupta Updated the answer – Gsk Jun 27 '18 at 10:19
  • what it means "not working"? which error is returned? – Gsk Jun 27 '18 at 10:39
  • 1
    Some file not found 2 exceptions were there – Ketan Gupta Jun 27 '18 at 10:42
  • After these lines of code do i have to add anything any where? – Ketan Gupta Jun 27 '18 at 10:44
  • In the line `"download.default_directory": r"C:\Users\xxx\downloads\Test",` you have to sobstitute the path `C:\Users\xxx\downloads\Test` with the path where you want the file to be saved – Gsk Jun 27 '18 at 10:52
  • options = Options() options.add_experimental_option("prefs", { "download.default_directory": r"C:\Users\\Downloads", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True }) driver = webdriver.Chrome(chrome_options=options) web_driver = webdriver.Chrome("WebDriver\\chromedriver.exe") – Ketan Gupta Jun 27 '18 at 10:57
  • where did you take `web_driver = webdriver.Chrome("WebDriver\\chromedriver.exe")`? Erase that line and use `driver` where you where using `web_driver` – Gsk Jun 27 '18 at 11:00
  • with the firefox also its not working same error is coming – Ketan Gupta Jun 27 '18 at 11:14