• 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 / Simple way to pass parameters to AutoIT script for file upload

Simple way to pass parameters to AutoIT script for file upload

June 3, 2016 by Mukesh Otwani 24 Comments

pass parameters to AutoIT script

Hi, all today I am going to share small tricks for Autoit, Thanks to my friend Lajish Lakshmanan who gave me this tip. In this post, we will discuss how to pass parameters in Autoit script for Selenium code.

Background

While uploading file in Selenium Webdriver using AutoIT we have hard coded the complete path so we cannot reuse that script for another test, which is actually bad practice.

We have to create a script in such way that we can reuse the scripts. In this case, we need to send parameters so that we can pass file in run time.

Please check below article before moving to passing parameter.

Upload file in Selenium using AutoIT

pass parameters to AutoIT script

 

Solution for pass parameters to AutoIT script

We can accept command line parameter in runtime using below command.

$CmdLine[1]

 

In my previous post, I have already discussed that part using parameters we can upload multiple files without creating multiple scripts.

AutoIT Script

We can use & symbol to add values in AutoIT.

Example

“Mukesh”&”Otwani”

 

Program for pass parameters to AutoIT script

 

//Wait 15 seconds for the Upload window to appear(Comments)

WinWait(“[CLASS:#32770]”,””,15)

 

//Set input focus to the edit control of Upload window using the handle returned by WinWait(Comments)

ControlFocus(“File Upload”,””,”Edit1″)

 

//Set the File name text on the Edit field. Last parameter will take file name on runtime(Comments)

ControlSetText(“File Upload”, “”, “Edit1”, “C:\FileUploads\Resume\”&$CmdLine[1])

 

Once you are done with script save the file > Compile the script > You will get the .exe file.

 

Program to call the file from Java program.

Runtime.getRuntime().exec(“Your-autoit-script-compiled.exe”+” “+”file-name-which-you-want-to-upload”);

 

Conclusion.

We have multiple ways to upload file in Selenium webdriver but you have to select which one will be best for you.

This is one of my short post but informative one, I hope you will implement in your project or in your future projects.

Please feel free to share your thoughts in comment section. Will see you in next post.

 

Filed Under: AutoIT

Reader Interactions

Comments

  1. Kalaiselvi says

    November 9, 2021 at 9:44 PM

    Hi,
    How I need to give the upload file name through the excel file? I have used dataprovider to get the excel data. Will it support in autoit?

    Reply
    • Mukesh Otwani says

      November 10, 2021 at 9:19 AM

      Hi Kalaselvi,

      Yes, it will. You will be reading data from an intended cell from excel file in String format and saving it in a variable. Pass the same variable to the AutoIT script via cmd line.

      Reply
      • Kalaiselvi says

        November 10, 2021 at 5:25 PM

        Thank you for clarifying the doubts. Suppose I want to give two parameters through excel means like first name and last name how it will map first parameter and second parameter?

        Reply
        • Mukesh Otwani says

          November 11, 2021 at 12:20 PM

          Hi Kalaselvi,

          You pass as many parameters as you want, just put space between those params. I would also recommend you to go through their official documentation also https://www.autoitscript.com/autoit3/docs/intro/running.htm

          Reply
  2. Yauwana Ravindra says

    October 12, 2020 at 5:37 AM

    Hi Mukesh,
    How can i run the AUTOit script using Jenkins or Bamboo in the cloud.will it run as usual as in the local machine or do I need to do few tweaks ?

    Thank you,
    Yauwana

    Reply
    • Mukesh Otwani says

      October 12, 2020 at 11:19 AM

      Hi Yauwana,

      Hopefully, it should work as it is. Be assure that path of file being used in AutoIt should be correct as location available in Jenkins Slave/Bamboo Agent machine. If these machines are linux machines then AutoIt executable will not work as it works only on Windows OS

      Reply
      • Yauwana Ravindra says

        October 12, 2020 at 11:38 AM

        Thank you for the reply Mukesh,
        What if I use Sikuli instead of AutoIt ?

        Reply
        • Mukesh Otwani says

          October 12, 2020 at 8:20 PM

          Hi Yuawana,

          Sikuli highly depends on screen resolution as Sikuli goes with image comparison. If you are sure about screen resolution stability then go ahead with it.

          Reply
  3. Laxman says

    August 29, 2019 at 9:44 PM

    Hi Mukesh,
    Please let me know how to call project location (user.dir) in AutoIT.

    Thanks in advance
    Laxman

    Reply
    • Mukesh Otwani says

      August 30, 2019 at 10:30 AM

      Hi Laxman,

      There are Macros in AutoIT. Please check this link https://www.autoitscript.com/autoit3/docs/macros.htm

      Reply
  4. Omkar says

    April 15, 2019 at 6:26 PM

    Hi Mukesh,

    If we Parameterize

    1.it is not updating path of 2nd document, still uploads the first one only

    Reply
    • Mukesh Otwani says

      April 15, 2019 at 9:48 PM

      Hi Omkar,

      AutoIT simply paste files path into file input box at bottom when you click on browse button so if you want to upload multiple file in one shot then you must paste file name like this “C:\Folder_1\File_1.txt” “D:\Folder_2\File_2.txt” …so on
      Also check whether your file upload control allows multiple file upload at same time.

      Reply
  5. harish says

    July 28, 2016 at 11:16 PM

    Hi sir, your tutorials are very useful and easy for beginners to learn….. sir let me know what is the difference between Implicit wait , Explicit wait, Fluent wait

    Reply
    • Mukesh Otwani says

      August 2, 2016 at 12:34 PM

      Hi Harish,

      I have article on this and will upload soon.

      Reply
  6. Raghavendra says

    June 13, 2016 at 11:44 AM

    Hi Mukesh,
    I was stuck on passing dynamic parameter with auto It. This post has resolved my issue clearly. Thank you very much for such a proper solution.

    Reply
    • Mukesh Otwani says

      June 14, 2016 at 9:12 PM

      Cheers Raghavendra 🙂

      Reply
  7. RaviKiran Reddy says

    June 8, 2016 at 3:09 PM

    HI Mukesh,

    Iam Ravi ,Working as Automation Engineer using selenium, I have found one problem with selenium,If Element is not exists in the Html page or DOM its take alot of time to find that element more than 5 min after 5 mins its executes next line of code I want if that element not exists in the page it immediately go to the next line of code but it takes more time.In Some cases element exists in page so I did if element exist then come this code otherwise go to else code I have a lot of cases like these so it takes a lot of take to execute complete code,I tried with all possible ways like list ,try and Catch but unable to reduce time,Can you please give any solution for this in selenium

    Reply
    • Mukesh Otwani says

      June 9, 2016 at 1:56 AM

      Hi Ravi,

      Are you using implicit wait of 5 min. Kindly use 5-20 seconds and try to use custom library for avoiding sync issue.

      Reply
    • Kamal Verma says

      March 6, 2021 at 8:37 AM

      Hi Ravikiran,
      Can you please help me on this.I am also facing the similar issue

      Reply
      • Mukesh Otwani says

        March 6, 2021 at 8:25 PM

        Hi Kamal,

        As already suggested, reduce time for implicit wait if defined considerably more. Then use a custom method using which check element with fluent wait.

        Reply
  8. Ritesh kumar says

    June 7, 2016 at 11:33 AM

    Hello sir,

    i am facing problem while uploading multiple files.

    here is my autoIT code
    WinWait(“[CLASS:#32770]”,””,15)
    ControlFocus(“File Upload”,””,”Edit1″)
    ControlSetText(“File Upload”,””,”Edit1″,”C:\Users\Ritesh_PC\Desktop”&$CmdLine[1])
    ControlClick(“File Upload”,””,”Button1″)

    Here is my script

    WebDriver d1 = new FirefoxDriver(fp);

    d1.manage().window().maximize();

    d1.get(“file:///C:/Users/Ritesh_PC/Desktop/fileupload.html”);

    //Demo

    WebElement ele= d1.findElement(By.xpath(“//input[@id=’file_u1′]”));

    ele.click();

    Runtime.getRuntime().exec(“C:/Users/Ritesh_PC/Desktop/m_j.exe”+” “+”Jellyfish.jpg”);

    Thread.sleep(3000);

    Runtime.getRuntime().exec(“C:/Users/Ritesh_PC/Desktop/m_j.exe”+” “+”Koala.jpg”);

    error is i am getting a pop up.

    Desktopjellyfish.jpg
    File not found
    Check the file name and try again

    Reply
    • Mukesh Otwani says

      June 9, 2016 at 2:01 AM

      Hi Ritesh,

      You forgot to add \

      old
      C:\Users\Ritesh_PC\Desktop

      new
      C:\Users\Ritesh_PC\Desktop\

      try and let me know.

      Reply
  9. Lajish Lakshmanan says

    June 4, 2016 at 3:37 PM

    Good Post…….
    Beneficial for all selenium testers

    Reply
    • Mukesh Otwani says

      June 9, 2016 at 2:03 AM

      Thanks Lajish for nice post.

      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?