Java – How to select multiple files using Windows File Explorer with selenium webdriver

How to select multiple files using Windows File Explorer with selenium webdriver… here is a solution to the problem.

How to select multiple files using Windows File Explorer with selenium webdriver

I’m automating a UI test that involves selecting files to upload, and I’m able to use this solution to automatically select files

WebElement filepath=driver.findElement(By.id("fileUploadId"));
filepath.sendKeys("C:\\TextFile.txt");

My question is that I need to select a lot of files to upload, should a special format be followed in the path I send? Because I tried the space-separated path but it didn’t work.

Solution

To upload multiple files, you can construct a string, adding all absolute paths to files delimited by \n< as follows:

WebElement filepath = driver.findElement(By.id("fileUploadId"));
filepath.sendKeys("C:/TextFile1.txt \n C:/TextFile2.txt \n C:/TextFile3.txt");

Citations

You can find some detailed documentation at:

Related Problems and Solutions