0

I'm accessing a page using a Selenium script I made in Python, however, when this page loads, it automatically asks me to save a .exe file. I'm using Firefox, so a dialog box comes up asking if I want to save the file or not.

Is it possible to add something in Selenium that stops this from happening? I couldn't find anything online about this.

I just want to clarify that I do not want it to automatically save the file - I want it to neither prompt nor actually download the file.

scob_
  • 277
  • 1
  • 11
  • What website? You can disable some stuff through Options and Prefs. – Arundeep Chohan Oct 06 '20 at 22:34
  • Please check this once https://stackoverflow.com/questions/41644381/python-set-firefox-preferences-for-selenium-download-location – Sariq Shaikh Oct 06 '20 at 22:34
  • Does this answer your question? [Set Firefox profile to download files automatically using Selenium and Java](https://stackoverflow.com/questions/36309314/set-firefox-profile-to-download-files-automatically-using-selenium-and-java) – SiKing Oct 06 '20 at 22:35
  • @SiKing Is there a way to reverse that so instead it automatically *ignores* downloads? – scob_ Oct 06 '20 at 23:10
  • @arundeepchohan Can I set it to ignore exe downloads - so I don't get prompted to save the file? – scob_ Oct 07 '20 at 00:47
  • application/x-msdownload is the type you want. – Arundeep Chohan Oct 07 '20 at 01:13
  • @arundeepchohan I know what MIME type a .exe is, so how can I tell Firefox to not allow downloads with mime type application/x-msdownload? I want it to not prompt me what to do and not download it. – scob_ Oct 07 '20 at 04:18
  • This is a basic function of the browser: if you click on a link (or if code in the page clicks on it for you), it will download it. This is not a Selenium problem, this is a browser problem. I think the best you might be able to do is to download it to `/dev/null`. – SiKing Oct 07 '20 at 15:15

1 Answers1

0

You could use pyautogui module to locate and click on the "No" button in the dialog box:

noButton = pyautogui.locateCenterOnScreen('noButtonScreenshot.png')
pyautogui.moveTo(noButton)
pyautogui.click()

Or use pyautogui sendkeys to hit the No button?

Failing that, you could set the browser preference to download the file but delete it once the browser session closes:

opts = Options()
opts.set_preference('browser.helperApps.deleteTempFileOnExit', true)