Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Upload multiple files in Selenium

Posted on 04/23/2025 By admin

Hello Folks,

This is an advanced concept. Beginners can ignore it as of now. I just found it while automating some functionality in mu company. So just thought of sharing.

Note: I assume, you have basic knowledge of AutoIT.

During automating the application, we come up with scenarios where we need to upload file. If it is single file upload, we can do it using sendKeys() method or AutoIT script. Problem happens when we need to upload a multiple files.

To upload multiple files we use ctrl key and select whatever files we want to upload and click on “Open” button.

But how to do it in Selenium??

After so many attempts of try, I finally got one solution, which I will share here.

HTML code of file upload input tag:

When we write “multiple” within tags, it becomes multiple file upload enable input tag. Save above html code with .html/.htm extension and open it and click on ‘choose file’.

How did I get an Idea?

When we select single file to upload, notice “File Name” text box:

When we select multiple files using ctrl key, then notice “File Name” text box:

Multiple file names are put in double quotes separately.

I replaced file names with absolute path as below:

And when I clicked on Open, it uploaded:

So, I concluded, if I am able to pass below string to the File Name text box, I can upload multiple files in single shot.

“F:\2017\MakeSeleniumEasy\SuportedFiles\demo2.txt” “F:\2017\MakeSeleniumEasy\SuportedFiles\demo1.txt”  

Now I stared exploring my options:

1.Using sendKeys():

When I passed above string, it gave error like its not absolute xpath. I used escape sequence to send double quotes but no luck.

2. Using Robot class:

It includes lot of key press and release which is irritating. I didn’t feel it easy.

3. Using AutoIT:

This worked!!!

In AutoIT , we can parameterized ControlSetText method. And I passed required string to ControlSetText method as below:

$vVariable = “””F:\2017\MakeSeleniumEasy\SuportedFiles\demo2.txt”” “”F:\2017\MakeSeleniumEasy\SuportedFiles\demo1.txt”””

ControlFocus(“Open”, “”, “Edit1”)

ControlSetText(“Open”, “”, “Edit1” ,$vVariable)

ControlClick(“Open”, “”, “Button1”)

Note: To pass double quotes in AutoIT script, we need to pass in to double quote only.

 I saved and compiled it.

JAVA code:

  public class MultiFileUpload { public static void main(String[] args) throws IOException, InterruptedException, Exception { System.setProperty("webdriver.chrome.driver","./exefiles/chromedriver.exe"); WebDriver driver= new ChromeDriver(); driver.get("file:///C:/Users/amodm/Desktop/demo.html"); driver.findElement(By.name("upload")).click(); Thread.sleep(5000); Runtime.getRuntime().exec("C:\\Users\\amodm\\Desktop\\script.exe");

}

}
 

 Please try above code and let me know if it works file. As I assume, you will be aware of that AutoIT works only in windows and code is different for each browser. So, kindly update the code as per your requirement.

Note: Kindly excuse for formatting as I am new to wordpress and still I need to learn many things.

Uncategorized

Post navigation

Previous Post: REST Assured Tutorial 16 – Building RequestSpecification Using RequestSpecBuilder
Next Post: Frequently Asked Java Programs 31 – Java Program to Find Common Characters in Two Given Strings

Related Posts

Make Selenium Easy – Page 3 of 57 – Uncategorized
Untitled Diagram (5) – Make Selenium Easy Uncategorized
InnerClassTestNg – Make Selenium Easy Uncategorized
Learn Selenium With Quiz – Basic Level 4 Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark