Pages

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
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=$oShell.windows   ; Get the 

collection of open shell Windows
$MyIExplorer=""
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
      $MyIExplorer=$Window
      exitloop
  endif
next
$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.

8 comments:

  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.

    ReplyDelete
  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!!!

    ReplyDelete
  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.
    Selenium

    ReplyDelete
  4. We can teach you Automation Anywhere from basic level to advance level. Please visit our website for more info: Best Automation Anywhere Training Institute in Chennai

    ReplyDelete
  5. Forex Broker Canada Forex Broker USA Top List Of Forex Brokers By Country. Compare Forex Brokers, Forex Trading Platforms & Forex Indicators.

    ReplyDelete
  6. Infycle Technologies, the top software training institute and placement center in Chennai offers the best
    Data science training in Chennai
    for freshers, students, and tech professionals at the best offers. In addition to Digital Marketing, other in-demand courses such as DevOps, Big Data, Cyber Security, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. Call 7504633633 to get more info and a free demo.

    ReplyDelete