Skip to content
VirtualLP Virtual Learning Platform

Practical 17: Automation using AutoIT

15 min read Topic 26 of 31 1 hands-on lab

Aim

Install AutoIT and write a script that selects a file in a Windows upload window. Call the script from a Selenium test. Check that the website receives the file.

Theory

Selenium controls the contents of a web page. A Windows Open window is part of the operating system, outside that page.

AutoIT can control Windows windows and buttons. In this exercise, it selects a file while Selenium handles the web page. The two tools work together.

two helpers

Selenium is a helper who can work only inside the web page. When you click Browse, Windows opens its own window – outside the page – and Selenium cannot touch it. AutoIT is a second helper who knows how to use Windows windows: it waits for the Open box, types the file path and presses Open. Selenium then carries on.

AutoIT scripts can type, click and control Windows dialogs. Save a script as .au3. You can compile it to an .exe file and start it from Java with Runtime.getRuntime().exec().

AutoIT tool Purpose
AutoIt3.exe Interpreter that runs .au3 scripts
SciTE4AutoIt3 Editor with syntax highlighting; F5 runs, Ctrl+F7 compiles
Aut2Exe Compiler – converts .au3 to .exe
AutoIt Window Info (Au3Info.exe) Finder tool to read a window’s Title, Class and a control’s ClassnameNN / ID

Key AutoIT functions

Function Purpose
WinWait("title", "", timeout) Wait until a window exists
WinWaitActive("title") Wait until it is active
WinActivate("title") Bring a window to front
ControlFocus("title", "", "Edit1") Focus a control
ControlSetText("title", "", "Edit1", "text") Set text in a control
ControlClick("title", "", "Button1") Click a button
Send("text{ENTER}") Simulate keystrokes
Sleep(ms) Pause
$CmdLine[1] First command-line argument
MsgBox(0, "Title", "Text") Show a message
Prefer sendKeys when possible

If the <input type="file"> element is accessible, Selenium can upload directly with element.sendKeys("C:\\path\\file.pdf") – no dialog appears. A styled button may still use an underlying file input that Selenium can fill. Use AutoIT here to study native Windows dialogs, not because every custom upload button requires it.

How the integration works

sequenceDiagram
    participant J as Selenium test (Java)
    participant B as Browser
    participant W as Windows "Open" dialog
    participant A as upload.exe (AutoIT)
    J->>B: click "Choose file" button
    B->>W: native file dialog opens
    J->>A: Runtime.exec("upload.exe C:\\files\\resume.pdf")
    A->>W: WinWaitActive("Open") · ControlSetText(Edit1, path) · ControlClick(Button1)
    W-->>B: file selected
    J->>B: click "Upload" and assert success message

Requirements

The .test addresses refer to the simulated practice app. Outside the simulator, use a running test app and its actual addresses and page elements.

  • Windows 10/11, AutoIt v3 (with SciTE4AutoIt3).
  • Eclipse project with Selenium WebDriver + JUnit/TestNG (Test Next Generation).
  • AUT (Application Under Test): VLP Demo Store → Profile → Upload resume page with a styled Choose file button that opens the native dialog, an Upload button and a success message “resume.pdf uploaded successfully”.
  • A test file C:\files\resume.pdf.

Procedure

Part A – Install AutoIT and explore the language

  1. Download and install AutoIt v3 (choose Run the script as the default action) and SciTE4AutoIt3.
  2. Open SciTE and run a first script with F5:
; hello.au3 – AutoIT basics
Local $name = "VirtualLP"
MsgBox(0, "Hello", "Welcome to AutoIT, " & $name)
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Automated by AutoIT{ENTER}")
  1. Open AutoIt Window Info and drag the Finder Tool onto the browser’s Open dialog:
    • Title: Open, Class: #32770
    • File name box: ClassnameNN Edit1
    • Open button: ClassnameNN Button1

Part B – Write the upload script

; upload.au3 – fills the Windows "Open" dialog with a file path passed as argument
; Usage: upload.exe "C:\files\resume.pdf"

If $CmdLine[0] < 1 Then
    MsgBox(16, "Upload", "Pass the file path as an argument")
    Exit 1
EndIf

Local $title = "Open"                      ; Chrome/Edge: "Open", Firefox: "File Upload"
If WinWait($title, "", 10) = 0 Then Exit 2 ; wait up to 10 s for the dialog
WinActivate($title)
WinWaitActive($title, "", 5)
ControlFocus($title, "", "Edit1")
ControlSetText($title, "", "Edit1", $CmdLine[1])
Sleep(500)
ControlClick($title, "", "Button1")       ; the "Open" button
Exit 0
  1. Save as C:\autoit\upload.au3.
  2. Compile: in SciTE press Ctrl+F7 (or right-click the file → Compile Script (x64)) → produces C:\autoit\upload.exe.

Part C – Integrate with Selenium WebDriver

package vlp.autoit;

import static org.junit.Assert.*;
import java.time.Duration;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.*;

public class FileUploadAutoItTest {

    private WebDriver driver;
    private WebDriverWait wait;

    @Before
    public void setUp() {
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        wait = new WebDriverWait(driver, Duration.ofSeconds(15));
        driver.get("https://demo.virtuallp.test/profile/upload");
    }

    @Test
    public void uploadResumeWithAutoIt() throws Exception {
        // 1. Open the native file dialog via the custom button
        driver.findElement(By.id("choose-file")).click();

        // 2. Let AutoIT fill and confirm the dialog
        Process p = Runtime.getRuntime().exec(new String[] {
                "C:\\autoit\\upload.exe", "C:\\files\\resume.pdf" });
        int exit = p.waitFor();
        assertEquals("AutoIT script exit code", 0, exit);

        // 3. Verify the chosen file name and upload
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("file-name"), "resume.pdf"));
        driver.findElement(By.id("upload")).click();

        WebElement msg = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".alert-success")));
        assertEquals("resume.pdf uploaded successfully", msg.getText());
    }

    @After
    public void tearDown() {
        if (driver != null) driver.quit();
    }
}
  1. Run the test (Run As → JUnit Test). Watch the browser click Choose file, the Windows dialog open, AutoIT type the path and press Open, and the page upload the file.

Virtual lab · Testing Tools · 40 min

Handle a Windows file-upload dialog with AutoIt

Run your first AutoIt script in SciTE, inspect the native “Open” dialog with AutoIt Window Info, write and compile upload.au3, and call the executable from a Selenium WebDriver test to upload a résumé.

Open lab

Output / Observations

Example output for the settings in this lesson:

  • upload.exe exits with code 0; the page shows resume.pdf as the selected file.
  • The success alert “resume.pdf uploaded successfully” appears and the JUnit test passes (Runs 1/1, Failures 0).
  • If the dialog title differs (for example Firefox uses File Upload), WinWait times out and the script exits with code 2 – the assertion on the exit code makes this failure obvious.

Conclusion

Check that AutoIT finds the correct window, enters the file path and clicks the Open button. Then check the website's upload result through Selenium.

Viva questions

  1. Why can't Selenium WebDriver handle native OS dialogs? They are operating-system windows, not part of the web page's DOM (Document Object Model) that WebDriver controls.
  2. What is AutoIT? What are .au3 files? A free BASIC-like scripting language for automating Windows GUIs (Graphical User Interfaces); .au3 files are its script files.
  3. What is the AutoIt Window Info tool used for? To find a window's title and class and a control's ID (for example Edit1, Button1) to use in the script.
  4. Explain WinWaitActive, ControlSetText and ControlClick. Wait until a window is active; put text into a control; click a control.
  5. How is an AutoIT script compiled and called from Java? Compile with Aut2Exe (right-click → Compile Script) to .exe, then run it with Runtime.getRuntime().exec(...) / ProcessBuilder.
  6. How can a file be uploaded with Selenium without AutoIT? Call sendKeys("C:\\path\\file.pdf") directly on the <input type="file"> element.
  7. What is $CmdLine in AutoIT? An array of command-line arguments passed to the script ($CmdLine[0] is the count, $CmdLine[1] the first argument).

Practise this topic

Hands-on virtual lab

Apply what you just read in a realistic, guided simulation. Free with a verified account.

Create a free account to track your progress and unlock virtual labs.