Upload File in Selenium Webdriver using Autoit

This guide will show you how to Upload File in Selenium Webdriver using Autoit Step by Step guide in a simple manner.

1-While automating web-application many times you will get window based activity like- file upload, file download pop-up, window authentication for secure sites etc.

In this case, Selenium fails and will not be able to handle desktop elements  to avoid this we will use AutoIT script that will handle desktop or windows elements and will combine AutoIT script with our Selenium code.

 

Introduction to AutoIT tool

1-AutoIt is freeware automation tool that can work with desktop application too.

2-It uses a combination of keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys).

For more info about AutoIT, you can visit their Official Website AutoIt Official Website

Upload File in Selenium Webdriver using Autoit

 

YouTube video for Same 

                    
How to write a script in AutoIT?

 

For AutoIt scripting, you should have three things ready.

1-AutoIt Editor- Editor helps us to write AutoIt scripts.

2-Tool Finder (Same as firebug on Firefox) – It will help us to identify the element and check their Attributes.

3- AutoIt Help section- This help you to understand about AutoIt functions and what are the parameter it accepts.

Let’s start with Downloading first

Step 1– Navigate to AutoIt  official website  https://www.autoitscript.com/site/autoit/downloads/  and go to download section or Click here Download AutoIt

Step 2– Click on Download AutoIt and Install

Step 3–  Click on Download Editor and Install.
Upload File in Selenium Webdriver using Autoit

 

Step 4– Once both installed in your machine check all is installed correctly.

Note- Generally it goes to C:\Program Files\AutoIt3 location if you do not change it

Upload File in Selenium Webdriver using Autoit

 

 

 Step5– Open SCiTE folder and  Click on SciTE this will open AutoIt Editor

 

Upload File in Selenium Webdriver using Autoit
Once all Installed Let’s see how we can write script

Upload File in Selenium Webdriver using Autoit

To Upload File in Selenium Webdriver using Autoit we need to take care of some steps so let’s begin

To upload a file in Selenium Webdriver we will create AutoIT script, which will handle file-uploaded window, and then we will combine Selenium script with AutoIt scripts.

Click on Upload button you will get file uploader we will handle the same using AutoIt.

 

Step 1- Open Editor and Finder Tool

Upload File in Selenium Webdriver using Autoit

 

Upload File in Selenium Webdriver using Autoit

 

 

 Step 2– We need to write script to upload file so we will use some method of AutoIt.
Each method will have some own functionality
ControlFocus-This will give focus on the window

ControlSetText-This will set the file path

ControlClick-This will click on button

 

Step 1- 

Click on Browse button , a new window will open now open finder tool and Click on Finder tool and drag to the file name as I shown in below screenshot.

 

Upload File in Selenium Webdriver using Autoit

This will give all the detail about that window and file name section info; we will use only some attribute like window title, class, and instance.

Open AutoIt Editor and Write Script

Upload File in Selenium Webdriver using Autoit

In ControlClick method we will give control id of open button

Step 2-

Save the script to a particular location with some unique name.

Note- By default script will be saved as .au3 extension

Step 3– Now Compile the script so for compiling right click on file and Select compile script this will generate a .exe file of the file.

 

Upload File in Selenium Webdriver using Autoit
Step 4- Now write Selenium program and add this .exe file and run your program

Here is the code

 

Thanks for Visiting my blog. Please leave a comment below if you are finding some issue while Upload File in Selenium Webdriver using Autoit.

Keep in touch. Have a nice day.

 

Now if you are comfortable with Basic Selenium, you can check out Advance Selenium Tutorial as well. 🙂

For More updates Learn Automation page

For any query join Selenium group- Selenium Group

26 Comments

  1. Deepak
      • Deepak
  2. Ritu Singh
  3. Vignesh
  4. Vignesh
  5. suresh
  6. Vikas
  7. jyothi
  8. Vicky
  9. snehita
  10. Thao

Leave a Reply