• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Advance Selenium / AutoIT / Upload multiple files in Selenium webdriver using AutoIT

Upload multiple files in Selenium webdriver using AutoIT

March 29, 2016 by Mukesh Otwani 23 Comments

Selenium Webdriver tutorial

This is my one of my favorite topic Upload multiple files in Selenium using AutoIT.

Recently in one of my requirement, we had to upload multiple times. We already know how to upload files in AutoIT but it is not recommended to create multiple AutoIT scripts for uploading files.

 

We can also upload files in Selenium using Sikuli and Robot class as well but AutoIT is the best way to do this.

 

I did some googling and finally came to know that using Command Line Parameter in AutoIT we can achieve this.

In this post, I am going to share how to parameterize AutoIT script and integrate into Selenium webdriver.

Upload multiple files in Selenium

 

I have created the video for the same.

 

 

Step 1- Edit AutoIT script

ControlFocus(“File Upload”,””,”Edit1″)
ControlSetText(“File Upload”,””,”Edit1″,$CmdLine[1])
ControlClick(“File Upload”,””,”Button1″)

 

If you focus on line number 2 where I have used $CmdLine[1] this is the way to pass parameter at run time.

In the same way, we can pass multiple arguments in AutoIT.

Example are-

$CmdLine[0] ; Contains the total number of items in the array.
$CmdLine[1] ; The first parameter.
$CmdLine[2] ; The second parameter.
$CmdLine[nth] ; The nth parameter e.g. 10 if the array contains 10 items.

 

Step 2- Pass parameters from Selenium script at run time.

Runtime.getRuntime().exec(“C:\\path \\filename.exe”+” “+”file which you want to upload.”);

 

Program to upload multiple files in Selenium Webdriver using AutoIT

package AutoITDemo;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class HandleMultipleWindow 
{

@Test
public void uploaMultipleFiles() throws Throwable
{
WebDriver driver=new FirefoxDriver();

driver.manage().window().maximize();

driver.get("file:///C:/Users/Mukesh_50/Desktop/My%20blog/AutoIT/Demo.html");

driver.findElement(By.xpath(".//*[@id='1']")).click();

Runtime.getRuntime().exec("C:\\Users\\Mukesh_50\\Desktop\\My blog\\AutoIT\\fileUpload3.exe"+" "+"C:\\Users\\Mukesh_50\\Downloads\\VerifyTitle.java");

Thread.sleep(2000);

driver.findElement(By.xpath(".//*[@id='1']")).click();

Thread.sleep(2000);

Runtime.getRuntime().exec("C:\\Users\\Mukesh_50\\Desktop\\My blog\\AutoIT\\fileUpload3.exe"+" "+"C:\\Users\\Mukesh_50\\Downloads\\HATHWAY.txt");
}
}

 

You can try this with Authentication as well in which you can pass username and password at run time which will save a lot of time for you.

If you want to explore authentication in Selenium using AutoIT then below post will help you.

 

How to handle authentication window in Selenium Webdriver using AutoIT.

 

I tried this multiple times and worked always. You can also try in local machine and let me know if you are still facing some issue.

 

 

Filed Under: AutoIT Tagged With: Upload multiple files

Reader Interactions

Comments

  1. Gauri says

    March 10, 2022 at 3:43 PM

    Hello Mukesh sir.
    Thanks for ythe Video for AutoIT. Its really helpful.

    I want to upload multiple file
    Test case – Click on upload button from Web page -> Attach one file -> return to Web Page -> click on Upload button -> attach one file.
    To achieve this I use below code :-
    WinActivate(“Open”)
    ControlFocus(“Open”, “”, “Edit1”)
    Sleep(1000)
    ControlSetText(“Open”,””,”Edit1″,$CmdLine[1])
    Sleep(700)
    ControlClick(“Open”,””,”Button1″)
    Sleep(5000)

    But when I am executing it, first file gets attached successsfully, but for second file, popup gets open but focus doesnt goes to “Edit1 control” and it doesnt click on Open button . Instead focus goes to the Web page and the next action continues on the Web page. Open dialog remains there on the screen.

    To resolve the issue, but no luck
    1. Added wait in AutoIT script
    2. Added wait in selenium script.
    Please suggest where I’m doing wrong.

    Regards
    Gauri

    Reply
    • Mukesh Otwani says

      March 17, 2022 at 12:35 PM

      Hi Gauri, in this case you need to call this different times with different arguments.
      Some actions
      Runtime.getRuntime().exec(“C:\\Users\\Mukesh_50\\Desktop\\My blog\\AutoIT\\fileUpload3.exe”+” “+”C:\\Users\\Mukesh_50\\Downloads\\HATHWAY1.txt”);
      Some Actions
      Runtime.getRuntime().exec(“C:\\Users\\Mukesh_50\\Desktop\\My blog\\AutoIT\\fileUpload3.exe”+” “+”C:\\Users\\Mukesh_50\\Downloads\\HATHWAY2.txt”);
      Some more actions
      Runtime.getRuntime().exec(“C:\\Users\\Mukesh_50\\Desktop\\My blog\\AutoIT\\fileUpload3.exe”+” “+”C:\\Users\\Mukesh_50\\Downloads\\HATHWAY3.txt”);

      Reply
  2. pouria says

    January 19, 2022 at 5:26 PM

    Hi
    Does it work with c# too?

    Reply
    • Mukesh Otwani says

      January 20, 2022 at 12:58 PM

      Hi Pouria,

      AutoIt works only on Windows OS. Programming language is no barrier over here

      Reply
  3. Shristi says

    September 27, 2021 at 12:15 PM

    Hi Sir,
    The video doesn’t have sound.
    Can you please re-upload the unmuted version.
    Thanks again.

    Reply
    • Mukesh Otwani says

      October 1, 2021 at 5:44 PM

      Hi Shristi,

      A new set of videos are on the way.

      Reply
  4. Premkumar says

    September 24, 2021 at 1:49 PM

    hi Mukesh,
    i am getting below error while uploading the file

    INFO: Detected dialect: W3C
    Exception in thread “main” org.openqa.selenium.InvalidArgumentException: invalid argument
    (Session info: chrome=93.0.4577.82)
    Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
    System info: host: ‘CHEAC3441L3599’, ip: ‘192.168.225.80’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘16.0.1’

    Reply
    • Mukesh Otwani says

      September 24, 2021 at 7:53 PM

      Hi Premkumar,

      Based in the URL shared, I can see for Choose File button. You can directly sendKeys action here with file path. This will do upload file action. Please go through initial part of this link https://learn-automation.com/upload-file-in-selenium-webdriver-using-robot-class/

      Reply
  5. divya says

    March 29, 2021 at 5:03 PM

    Hi,i tried to upload multiple files using AutoIT
    I think it will be helpful for someone
    ControlFocus(“Open”,””,”ToolbarWindow323″)
    Sleep(300)
    ControlSetText(“Open”,””,”ToolbarWindow323″,”E:\divya\pythonProject\99_22″)
    sleep(2000)
    ControlFocus(“Open”,””,”Edit1″)
    Sleep(200)
    ControlSetText(“Open”,””,”Edit1″,”E:\divya\pythonProject\99_22″)
    Sleep(300)
    ControlClick(“Open”,””,”Button1″)
    sleep(1000)
    MouseClick(“left”,650,360,1,20)
    sleep(1000)
    Send(“^a”)
    sleep(300)
    ControlClick(“Open”,””,”Button1″)

    Reply
  6. Pooja says

    November 14, 2019 at 4:43 PM

    I need to download a file and upload the same file .also i need to do this for multiple customers.For 1 customer download a file and upload it .similarly need to do this for multiple customers.

    Reply
    • Mukesh Otwani says

      November 14, 2019 at 11:38 PM

      Hi Pooja, where you are facing issue? I mean while uploading or downloading?

      Reply
  7. satveer bajwa says

    June 17, 2019 at 7:22 PM

    Hi Mukesh,
    I am trying to upload multiple files but I am getting error this file not found . Please check code

    //click on upload option

    driver.findElement(By.xpath(“/html/body/div[2]/div[5]/div/div/div/div[2]/div[2]/div[1]/div/div[1]”)).click();

    //upload pictures using Auto It
    Runtime.get Runtime().exec(“E:\\uploadpic multifinAL.exe”+” “+”E:\\QA\\upload test pictures\\14-dc-wedding-photos-white-umbrella.jpg”);
    //click on upload option

    driver.findElement(By.xpath(“/html/body/div[2]/div[5]/div/div/div/div[2]/div[2]/div[1]/div/div[1]”)).click();

    //upload pictures using Auto It
    Runtime.getRuntime().exec(“E:\\uploadpic multifinAL.exe”+” “+”E:\\QA\\upload test pictures\\beautiful_fantasy_world-wide.jpg”);

    Reply
    • Mukesh Otwani says

      June 18, 2019 at 2:32 PM

      Hi Satveer,

      File not found is not an info message that path/format of path which you have mentioned is incorrect. Kindly check it again

      Reply
      • satveer bajwa says

        June 19, 2019 at 5:44 PM

        Hi Mukesh,
        Thank you for your answer, I tried with other method like I added mutiples files in the editor so It works now.
        ControlSetText(“File Upload”,””,”Edit1″,”””E:\QA\upload test pictures\abc.jpg””””E:\QA\upload test pictures\mother-and-baby-indoors-hugging-and-smiling.jpg”””

        Thank you again.

        Reply
        • Mukesh Otwani says

          June 20, 2019 at 9:42 AM

          Great Satveer…:)

          Reply
  8. HarishPrabhu says

    April 22, 2019 at 5:34 PM

    Hi Mukesh,
    How to upload different files in multiple windows in selenium java?

    Reply
    • Mukesh Otwani says

      April 23, 2019 at 12:26 AM

      Hi Harish, In this case, you need to pass files as a parameter.

      Reply
  9. Abhilash Reddy.S says

    March 28, 2019 at 12:33 PM

    hi Mukesh,

    while i am running mt code for multiple file uploads, I am getting this below error. Please help me to get ride it.

    Exception in thread “main” java.io.IOException: Cannot run program “G:\Selenium”: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)

    Reply
    • Mukesh Otwani says

      March 28, 2019 at 12:54 PM

      Hi Abhilash,

      Did you provide actual path of AutoIt executable file because from error, it is saying that specified file path is not available. Kindly check your code once again.

      Reply
  10. jayashree says

    February 21, 2017 at 11:24 AM

    Hey hi mukesh,
    when m trying to upload the multiple files using Auto it i got this error”array variable has incorrect number of subscripts or subscript dimension range exceeded autoit”

    Reply
    • Mukesh Otwani says

      February 21, 2017 at 2:32 PM

      Hi Jayashree,

      Are you passing exact file path and syntactically correct?

      Reply
  11. Arun Jadhav says

    November 30, 2016 at 5:09 PM

    Hi Mukesh,

    How do we upload multiple files using single Runtime statement and multiple Commandline parameters in the autoit script?

    Like, I would like to provide multiple input parameters as the files using the following
    ControlSetText(“File Upload”,””,”Edit1″,$CmdLine[1])

    the Runtime.getRuntime.exec(“Path to .exe file”+” “+”list of file names to be provided here”); statement must pick multiple files from the input parameters

    Reply
    • Mukesh Otwani says

      November 30, 2016 at 5:28 PM

      Hi Arun,

      As per my video you can pass multiple files but one by one as parameter.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?