How to use AutoIT to upload a file in selenium web driver

AutoIt is a Beginner's All-Purpose Symbolic Instruction Codescripting language and automation tool for the Windows operating system. It offers a simple syntax and many built-in functions that allow you to automate the GUI interactions, keyboard inputs, and mouse movement.

AutoIt, combined with selenium, allows testers to automate web apps with enhanced functionality. Following are the steps to upload a file in Selenium web driver using AutoIt.

Note: This Answer assumes you have AutoIt and Selenium set up on your device.

Build an AutoIt script

Write a ControlFocus method used to set the keyboard focus to a specific control within a window method. ControlFocus method is used to set the keyboard focus to a specific control within a window

Test script
Test script

Here "File Upload" is the window title containing the control, and "Edit1" is the control class to set focus to.

You need to save it as test.au3 to test it. Then hold the F5 key. This will execute the statement and display the result in the script editor window. Next, complete the script by using the commands ControlSetText (command for setting the text in the edit field) and ControlClick (command used for click action).

AutoIt script
AutoIt script

Conversion

Save the script in .au3 format and convert it into .exe by right-clicking on the .au3 file and selecting “Compile Script.”

Integrate the file into Selenium

Now call the .exe file created in the directory to your test script in Selenium by using this command:

Runtime.getRuntime().exec("C:\AutoIt\Test.exe")

The complete test will be as follows:

package practiceTestCases;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AutoIt {
private static WebDriver driver = null;
public static void main(String[] args) throws IOException, InterruptedException {
// New instance for the Firefox driver
driver = new FirefoxDriver();
// Set element visibility wait time
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// Open your website
driver.get("https://websitename.com");
// Click on element to begin file upload
driver.findElement(By.id("elementname")).click();
// File upload dialog handled by executing script
Runtime.getRuntime().exec("C:\\AutoIt\\Test.exe");
// Allow time for file to upload
Thread.sleep(6000);
// Close the browser
driver.close();
}
}

Verify the output on your website and check if the file is uploaded.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved