Search This Blog


Sunday, September 26, 2010

How to click on browse button in selenium with the help of AutoIT

Recently, I had the challenge of writing some automation for a work flow which included uploading a file, and then downloading a file later in the work flow.
Autoit is a freeware windows testing tool. Autoit allows you accessing windows components similar to QTP. Basically once you have identified the id of the component on the screen you can use it by either clicking on it, typing in something. Using Autoit we can identify the internet explorer “Choose file” or Firefox

“File Upload” windows and enter the correct value to the input

field after which you will press the open button.

Step to click on browse button.
Step 1.
Download the AutoIT and intall it.

Download AutoIT

setp 2.
write a AutoIT script to click on browse button and save it.

#include <IE.au3>
; Internet Explorer is partly integrated in shell.application
$oShell = ObjCreate("shell.application") ; Get the Windows 

Shell Object
$oShellWindows=$   ; Get the 

collection of open shell Windows
for $Window in $oShellWindows    ; Count all existing 

shell windows
  ; Note: Internet Explorer appends a slash to the URL in it's 

window name
  if StringInStr($Window.LocationURL,"http://") then
$oForm = _IEGetObjByName ($MyIExplorer, "UploadedFile")
_IEAction($oForm, "click")

setp 3.
Compile AutoIT script and make exe file 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.

setp 4.
Call that exe in selenium.

Process proc = Runtime.getRuntime().exec("C:\\Documents and Settings\\nirkumar\\Desktop\\Browse.exe");

This will click on browse button and open choose file or upload file dialog box.
Download AutoIT script
Download exe of that script

If you want to test this script works then download the exe and open the page which has browse button and run(double click on this exe) this exe file. i am sure this
will click on your browse button and open a dialog box. If it does not then definitely your browse button has some other name than "UploadedFile" then in the step 2 change the button name and make exe of that script and run it.

NOTE: This will work in Internet explorer.


  1. Whats about firefox and other browser? do u have code to click on browse button in other browser ?
    Note : In our application, Browse button is a html element.

  2. Process proc = Runtime.getRuntime().exec("C:\\Documents and Settings\\nirkumar\\Desktop\\Browse.exe");

    How to Call that exe in selenium for C# language the example you gave its for java I think

    Please help!!!

  3. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium