How to upload multiple files to Chrome with Capybara / Selenium?

I am using Capybara with Chrome and Selenium. When I try to click a link that causes an automatic download, the file loads correctly. If I try to do this again, Chrome will display a message: "This site is trying to upload multiple files. Do you want to allow this?"

enter image description here

I was looking for a flag that could be used to disable this message, but could not find anything. Is there a way around this message and allowing multiple downloads without having to resort to refreshing the page? (For example, is there a way I can click the Allow button programmatically?)

+6
source share
3 answers

Use Chrome Options

WebDriver driver = null; ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_settings.popups", 0); prefs.put("profile.content_settings.pattern_pairs.*.multiple-automatic-downloads", 1 ); //Turns off download prompt prefs.put("download.prompt_for_download", false); options.setExperimentalOption("prefs", prefs); driver = new ChromeDriver(options); 
0
source

If there is no better solution, you can get the item and click on it.

 driver.findElement(By.xpath("xpath")).click(); 
-2
source

All Articles