Andy Feely Andy Feely - 1 year ago 121
Python Question

Python Selenium Chrome disable prompt for "Trying to download multiple files"

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?

Answer Source

Did you try passing the according preference to webdriver?

import os
from selenium import webdriver
from import Options

chromedriver = "path/to/chromedriver"

os.environ[""] = 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):