Tuesday, April 17, 2012

How to Upload / Attach any file or document with Selenium RC



Steps that need to follow
1. In order to upload files we need to have AutoIT (freeware BASIC-like scripting language designed for automating the Windows GUI -- keystrokes, mouse actions ).
2. Download AutoIT software from http://www.autoitscript.com/site/autoit/downloads/
3. Install upon clicking the downloaded AutoIT.exe file
4. If you want to upload a file into your application/system, create a document (Ex: lets say uploadFile.doc )
5. Next step is go to any folder in your drive and right click --> New --> AutoIT v3 Script    and select script.
6. It will open up AutoIT v3 script file, enter the following code at last and save the file as if you save any document with some name (Ex: lets say attachDocScript.au3  )


WinWaitActive("Choose File")
Send("C:\Program Files\AutoIt3\uploadFile.doc")   // specify your own path where attaching document is located.
Send("{ENTER}")


7. Close the AutoIT script file and right click on this, select compile the script -- which generates .exe file of the same. (Ex: attachDocScript.exe )
8. In your selenium program enter the following code after clicking the attach button from your application.


try {
String[] commands = new String[]{};
commands = new String[]{"C:\\Program Files\\AutoIt3\\attachDocScript.exe"}; //location of the autoit executable
Runtime.getRuntime().exec(commands);
    }
catch (IOException e) {}


9. Now run your progam. you Can see that you uploaded the document in your application successfully.

No comments:

Post a Comment