Thursday, December 30, 2010

Selenium - Handle Upload Dialog

Download
Handle_File_Upload.exe



Following is the Autoit Script to handle upload dialog box.

;--------------------------------------------------------------------
;~ File_Upload_FF.au3
;~ Purpose: TO handle the file Upoload dialog
;~ Usage: File_Upload_FF.exe "Dialog Title" "Path of the file"
;~ Create By: Gaurang Shah
;~ Email: shahgomji@gmail.com
;--------------------------------------------------------------------

AutoItSetOption("WinTitleMatchMode","2") ; set the select mode to select using substring

if $CmdLine[0] < 2 then
; Arguments are not enough
msgbox(0,"Error","File_Upload_FF.exe 'Dialog Title' 'Path of the file'")
Exit
EndIf

; wait Until dialog box appears
WinWait($CmdLine[1]) ; match the window with substring
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
WinActivate($title)

WinWaitActive($title)
ControlSetText($title,"","Edit1",$CmdLine[2])
ControlClick($title,"","&Open")

You need to download Autoit in order to run this script else you can download the EXE uploaded here.

To know how to call this EXE from JAVA read the following blogpost.
http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html