6

I am currently running a Python automator which needs to download multiple files within the same session using Selenium Chromedriver.

The problem is that when the browser attempts to download the second file and read it, the browser will not download until the "Allow" button has been clicked.

I have researched the ChromeOptions part of Selenium to do with disabling it, but many of the answers were in Java, or even other browsers.

To summarise, how do you disable the prompt for allowing multiple file downloads?

Andy Feely
  • 225
  • 2
  • 9
  • possible duplicate of [Disable chrome download multiple files confirmation](http://stackoverflow.com/questions/15817328/disable-chrome-download-multiple-files-confirmation) – adrianus Jul 15 '15 at 12:37
  • Hi adrianus, I had previously viewed this and other questions asked already, none of these answer my question though unfortunately. – Andy Feely Jul 15 '15 at 12:55

2 Answers2

12

Did you try passing the according preference to webdriver?

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

chromedriver = "path/to/chromedriver"

os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = Options()

# this is the preference we're passing
prefs = {'profile.default_content_setting_values.automatic_downloads': 1}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

# just downloading some files...
for _ in range(5):
    driver.get("http://code.jquery.com/jquery-1.11.3.min.map")

driver.quit()
rcambrj
  • 580
  • 3
  • 8
adrianus
  • 2,838
  • 1
  • 16
  • 37
  • Yeah unfortunately that doesnt work either. I just have my browser click on a button which causes the download. driver.find_element_by_xpath('//*[@title="title"]').click() – Andy Feely Jul 15 '15 at 13:42
  • 1
    Try again please, I had an error in the `prefs`-string. – adrianus Jul 15 '15 at 13:47
0

The only 2 prefs I've ever had to set are:

download.prompt_for_download = False
download.default_directory = "/path/to/folder/"
user2426679
  • 2,131
  • 1
  • 24
  • 28