1

I used the following Chrome Options but without success I always get the warning message that says "This type of file can harm your computer..."

options = Chrome_Options()
options.add_argument('--safebrowsing-disable-download-protection')
options.add_argument('download.default_directory=C:\\temp')

Could it be that these preferences are obsolete ?

How can I successfuly manage to download a file automatically to a certain path ?

I know that this question looks like several other questions that were asked before but I have tried to use the answers in those questions and it didn't solve my problem. Seems like this has something to do with the Chrome version and probably the past solutions were fir to old Chrome versions

EDIT To sum it all up the problem is that in Chrome v74 the automatic download is performed but a certain security mechanism doesn't let me save it. I still didn't manage to overcome this. I have also tried ChromeDriver v75 (with Chrome v75) without success.

Moshe S.
  • 2,834
  • 3
  • 19
  • 31
  • @DebanjanB as you can see I have done a sort of a research before I asked this question. I have tried all the suggestions but without success. The reason that I asked this question which is explained by the title is that I believe that Chrome v74 acts in a different manner regarding the issue that I see – Moshe S. Jun 06 '19 at 06:44
  • @DebanjanB I am more close than before to the solution thanks to the link that you attached to this question. My problem now is that Chrome opens a "Save As" dialogue instead of saving automatically to the specified folder – Moshe S. Jun 06 '19 at 10:20
  • Check the file extension properly through Dev tools and update this `'download.extensions_to_open': 'xml'` preference accordingly. – undetected Selenium Jun 06 '19 at 10:22
  • @DebanjanB First of all thank you very much. What do you mean by checking through Dev Tools ? Second thing I see some weird behavior. When I change the following dictionary entry ' 'download.default_directory': 'C://temp', ' it started to download automatically but I got an error 'Path Too Long'. By the way, I am running over a Windows environment what Path scheme should I use '/' or '\' ? – Moshe S. Jun 06 '19 at 10:32
  • Check [Failed-Path Too Long error after downloading csv file using ChromeDriver and Chrome Browser launched by Selenium through cygwin in Python](https://stackoverflow.com/questions/53757965/failed-path-too-long-error-after-downloading-csv-file-using-chromedriver-and-chr/53760537#53760537) – undetected Selenium Jun 06 '19 at 10:45
  • I will do that once I will see that I reach the solution. Currently I don't see the solution – Moshe S. Jun 06 '19 at 10:48
  • In my case I am not downloading an xml file. And I only want to download it automatically and save it in a certain location. What is the meaning of the 'extensions_to_open' does it try to open any of the downloaded files after the download ? – Moshe S. Jun 06 '19 at 10:54
  • @DebanjanB I removed the ''download.extensions_to_open': 'xml'' entry and now I see that when I use this path 'C:\temp' I get the 'Save As' dialogue and when I use 'C:\\temp' I get the "This type of file can harm your computer..." message. – Moshe S. Jun 06 '19 at 11:12
  • @DebanjanB disable duplicate as problem is different. Its due to chrome own virus protection. – Mithun Mandal Jun 06 '19 at 14:32
  • @DebanjanB you marked this question as duplicate. I am asking to remove what you marked. As problem is different. If it is a same problem then it would be resolved by now. – Mithun Mandal Jun 06 '19 at 14:38
  • @MithunMandal Can you explain us how the error _...This type of file can harm your computer..._ is different from the duplicate target? – undetected Selenium Jun 06 '19 at 14:41
  • @DebanjanB by using the following pref ''download.extensions_to_open': 'cfg'' I managed to open the file. So now I am missing the save. By default the Notepad application was the one that was used for this file. Do you have any suggestion regarding how to save the file at this point ? – Moshe S. Jun 10 '19 at 08:03
  • @MosheS. I think this question was regarding how to initiate download but not how to bypass the `Save As` dialogue. – undetected Selenium Jun 10 '19 at 08:13
  • @DebanjanB My goal is to be able to automatically download a certain file by using Chrome. But, when I realized that there is a certain limitation (in Chrome) I started searching for a workaround. I believe that I won't be the only one who would like to have this kind of workaround – Moshe S. Jun 10 '19 at 08:18

1 Answers1

1

try this.

    options = webdriver.ChromeOptions()
    # options.headless = True
    # options.add_argument("--headless")
    options.add_argument("--no-sandbox")
    options.add_argument("--ignore-certificate-errors")
    options.add_argument("--safebrowsing-disable-download-protection")
    # options.add_argument('--disable-gpu')
    options.add_argument('start-maximized')
    options.add_argument('--start-maximized')
    options.add_experimental_option("prefs", {
        "download.default_directory": self.downlaodpath,
        "download.prompt_for_download": False,
        "download.directory_upgrade": True,
        "safebrowsing.enabled": True
    })

Let me know if that fixed.

  • Thanks for the answer but I still get the annoying message that asks me to choose whether to Keep or Discard the file. The only setting that applies is the folder – Moshe S. Jun 05 '19 at 13:40
  • in your case these preferences did the job ? – Moshe S. Jun 05 '19 at 14:17
  • Yes it is. I am on python 3.xx and its downloading files. downlaodpath should be absolute path. I am on windows running Chrome Version 74.0.3729.169. chrome driver downloaded for chrome 74. – Mithun Mandal Jun 06 '19 at 13:37
  • what path format did you use ? with forward/backward Slash which OS are you working on – Moshe S. Jun 06 '19 at 13:40
  • OS: window 10. path example: ```os.path.abspath('./logs')``` – Mithun Mandal Jun 06 '19 at 13:42
  • If it is still not working then check in setting if "Ask where to save each file before downloading" is disabled or enabled. if enabled then disable it. – Mithun Mandal Jun 06 '19 at 13:52
  • It is disabled. And I still get the Keep/Discard notification – Moshe S. Jun 06 '19 at 13:58
  • got it. That means you are downloading either exe, msi or executable files which by default it will ask keep or discard. try disabling ```safebrowsing.enabled``` with false ```False```. And let me check how i can disable it. . – Mithun Mandal Jun 06 '19 at 14:05
  • In my case the prefs I am using the 'safebrowsing.enabled' is already in False as @DebanjanB recommended – Moshe S. Jun 06 '19 at 14:11
  • By the way, I am downloading a proprietary cfg file – Moshe S. Jun 06 '19 at 14:17
  • i just found something on [Superuser](https://superuser.com/questions/678601/disable-chromes-built-in-automatic-virus-scanning-of-downloaded-files). use ```options.add_argument("--safebrowsing-disable-download-protection")``` – Mithun Mandal Jun 06 '19 at 14:27
  • Sorry, but I already tried it as @DebanjanB recommended – Moshe S. Jun 06 '19 at 14:34
  • I did not see DebanjanB recommended use of ```options.add_argument("--safebrowsing-disable-download-protection")``` . Can you please try with it? – Mithun Mandal Jun 06 '19 at 14:39
  • I am using this option and still get the Keep/Discard – Moshe S. Jun 06 '19 at 14:42
  • 1
    It look like recent browser removed this [configuration](https://bugs.chromium.org/p/chromium/issues/detail?id=74848) and behavior is default and you cant disable it. If possible switch to firefox. – Mithun Mandal Jun 06 '19 at 14:56
  • FireFox is actually 100% functional in this scenario. I am running my test on both browsers as we're supporting both. Chrome is actually the prioritized one. So you are actually saying that it is impossible in my case of .cfg file to download it automatically without getting the Keep/Discard notification ? Aren't you familiar with at least a manual way to do this ? – Moshe S. Jun 06 '19 at 15:01
  • I checked with [All Option](http://chromedriver.chromium.org/capabilities) and find nothing. It may be your test site downloadable file comes with different mime type which tells chrome its harmful or the testing site or url has some text which could be malicious. other then i dont find any issue with code. You may try all possible option given their. – Mithun Mandal Jun 06 '19 at 15:09