
👉AutoIT in Selenium WebDriver
What is AutoIT in Selenium?
AutoIT in Selenium WebDriver : AutoIT is a free scripting language used to automate Windows GUI operations. When working with Selenium WebDriver, it’s often necessary to handle system-level pop-ups like file upload windows, which Selenium alone cannot control. This is where AutoIT becomes incredibly useful. It simulates keyboard actions, mouse clicks, and window controls to handle these native OS elements.
👉Table of Contents:
- Why Use AutoIT with Selenium?
- How to Download and Install AutoIT
- Using AutoIT for File Uploads
- Integrating AutoIT with Selenium WebDriver
- Conclusion
👉Why Use AutoIT with Selenium?
AutoIT in Selenium WebDriver : Selenium WebDriver cannot interact with Windows-based pop-ups such as file upload dialogs, print pop-ups, or native apps like Notepad and Calculator. AutoIT overcomes this limitation by allowing automation of Windows GUI elements that Selenium cannot handle.
👉 How to Download and Install AutoIT
- Visit the
- Navigate to the Downloads section and download both:
- AutoIT (the main scripting tool)
- AutoIT Script Editor (SciTE)
- Install both
.exe
files on your system. - After installation, open the editor from: javaCopyEdit
C:\Program Files (x86)\AutoIt3\SciTE\SciTE.exe
- Also, open AutoIT Element Identifier from: javaCopyEdit
C:\Program Files (x86)\AutoIt3\Au3Info.exe
🔍 Note: Element Identifier helps in inspecting Windows GUI elements and is similar to the Selenium IDE.
👉 Using AutoIT for File Uploads
AutoIT in Selenium WebDriver : Let’s walk through an example of uploading a file using AutoIT on a web page form.
Step 1: Identify Elements
- Open
Au3Info.exe
. - Click the “Choose File” button on the form.
- Drag the Finder Tool to the file name input box.
- Capture:
- Title:
Open
- Class:
Edit
- Instance:
1
- Control ID:
Edit1
- Title:
Step 2: Open AutoIT Script Editor
Go to:
javaC:\Program Files (x86)\AutoIt3\SciTE\SciTE.exe
Start writing your script using the following methods:
autoitControlFocus("Open", "", "Edit1")
ControlSetText("Open", "", "Edit1", "C:\path\to\your\file.doc")
ControlClick("Open", "", "Button1")
âś…
ControlFocus
– focuses the cursor on the input field
âś…ControlSetText
– sets the file path
âś…ControlClick
– clicks the “Open” button
Step 3: Compile the Script
- Save the script as
FileUpload.au3
- Right-click the file → Compile Script (choose 32-bit or 64-bit based on your OS)
- This generates an
.exe
file (e.g.,FileUpload.exe
)
👉 Integrating AutoIT Script with Selenium WebDriver
AutoIT in Selenium WebDriver : Now, use the compiled AutoIT script in your Selenium test case:
âś… Example Java Code:
javaimport java.io.IOException;
public class FileUpload {
public static void main(String[] args) throws IOException {
// Selenium code to click the 'Choose File' button
// driver.findElement(By.id("uploadButton")).click();
// Call the AutoIT script to handle the file upload
Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe");
}
}
- After clicking the file upload button in Selenium, control shifts to AutoIT to complete the file upload process.
- Once done, Selenium resumes and continues the test flow.
👉Conclusion
To handle Windows-based file upload pop-ups in Selenium:
- Install AutoIT and its script editor.
- Use Element Identifier to inspect GUI elements.
- Write and compile your AutoIT script.
- Call the
.exe
script from Selenium.
By using AutoIT with Selenium WebDriver, you can effectively automate actions that are otherwise impossible with Selenium alone — such as interacting with non-HTML elements or native OS pop-ups.
Robot Class in Selenium