How to avoid this issue using selenium and python
Asked
Active
Viewed 528 times
0
-
2Possible 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 Answers
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
-
-
-
1
-
-
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
-