Thursday, 16 October 2014

Uploading a file using AutoIT scripts in Selenium Web driver

Uploading a file using AutoIT scripts in Selenium Web driver

AutoIT is a tool for desktop automation. Using AutoIT, you can write scripts for automating desktop-based application and convert them in to an executable file.
Selenium is not capable to to access windows components and it will be handled through AutoIT.

Once you are able to click on browse button and a dialog box is open to choose the file then you just run a AutoIT script which will help to select the file from your local or remote drive and control will come to your web page to proceed with selenium.

Steps to upload a file using AutoIT scripts in Selenium Web driver

    1.    Download AutoIT from http://www.autoitscript.com/site/autoit/downloads/


    2.    Keep the AutoIT file in your project location, along with the file to be uploaded.


   3.    Now edit the UploadFile.au3 using notepad and make the following changes

    WinActivate("Choose file");
   Local $file = "c:\yourpath\howtoupload.doc"
   ControlSetText("Choose file", "", "Edit1", $file)
   ControlClick("Choose file", "", "Button2")

   4.    Complie AutoIT script and make exe of that script.

Right click on that saved script file and click on "Compile script" from context menu. This will make an exe file of that script.


   5.    Call that exe in selenium code

try
            {
            //Runtime.getRuntime().exec("D:\\MMR_Automation_Final\\MMRAutomation\\AutoITScript\\UploadFile.exe");
                  Runtime.getRuntime().exec(System.getProperty("user.dir")+"\\AutoItFiles\\UploadFile.exe");
            }
            catch(Exception e)
            {
                  e.printStackTrace();
            }











No comments:

Post a Comment