Upload a file using AutoIT in Selenium-Webdriver

Generally we face a problem while uploading a file in selenium.Because we know that selenium only supports web based applications.In order to suppress this we need to use AutoIT.For example you wanna upload your a file in Gmail-compose. what you gonna do ???

What is AutoIT ? AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

We need to call the AutoIt script after clicking on the upload button. Immediately after clicking on Upload button, the control should be transferred to AutoIt by the below statement which takes care of uploading the file .

Follow the Steps to upload a file :

Step 1. Download and install AutoIT from Click here.

Step 2.Once you install it, you will notice ‘Script Editor’ in the directory

Step 3.Open Script Editor and type

WinWaitActive(“File Upload”)



Step 4.Now save the file as ‘sample’

Step 5.Right click on the saved file and click ‘Compile script’

step 6. ‘sample.exe’ file should be generated.

Now to run this .exe file using java, Place this in your code.

‘ Runtime.getRuntime().exec(“D:\\Dollar\\AdvProject\\sample.exe”); ‘

Please follow the class for the reference.

public class FileUpload {

private static WebDriver driver;
String URL = “http://www.xyz.com”;
public void testFileUploading() throws InterruptedException, IOException
driver = new FirefoxDriver();
WebElement ele = driver.findElement(By.id(“id of browse button”));

Disadvantage : AutoIT supports only for windows.It wont support for ‘mac’

One thought on “Upload a file using AutoIT in Selenium-Webdriver

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s