Python Selenium Chrome disable "Try to upload multiple files" prompt

I am currently running a Python automaton that needs to upload multiple files to the same session using Selenium Chromedriver.

The problem is that when the browser tries to download the second file and read it, the browser won't load until the "Allow" button is clicked.

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

To summarize , how do you disable the prompt to allow multiple file uploads?

+3


source to share


2 answers


Have you tried passing the appropriate preference 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()

      

+2


source


The only two prefs I've ever had to install are the following:



download.prompt_for_download = False
download.default_directory = "/path/to/folder/"

      

0


source







All Articles