Upload a file using AutoIT
About AutoIT:
AutoIt v3 is a freeware BASIC-like scripting language designed for automating Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks.
This method is for handling the Windows File Upload dialog, which cannot be handled using Selenium. Please follow the below steps:
Download AutoIT
Open SciTE Script Editor
Below script is used to detect the windows file upload dialog
WinWaitActive("File Upload") //File Upload is the dialog's title Send("Full path of the document") Send("{ENTER}")
Save the above script file as
Script.au3
Compile the file from SciTE Editor and you will get an
Script.exe
file
Steps to be followed while running the test:
Click on the File Upload / Choose File button, so that the File Upload dialog is displayed.
driver.findElement(By.id("uploadbutton")).click;
Invoke the
Script.exe
fileRuntime.getRuntime().exec("Script.exe");
The
Script.exe
file will handle the file upload