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

1 comments:

Anonymous said...

Instead of doing this, what you can do is set Selenium in *chrome mode and use the selenium.attachFile(String fieldLocator, String fileLocator) method. By setting Selenium in the *chrome mode, you are bringing down the heightened security restrictions. Javascript is not allowed to upload a file when the input type is file as that can possibly used to upload malicious files into a server.

Post a Comment