Drag and Drop the files into application

Share this post
FaceBook  Twitter  Mixx.mn     


To Drag a File saved in local computer and drop into the application, use following code:
Steps:
1) Identity the Object where the file to be dropped

2) Read x & y location of the Object

3) Open the folder in explorer from where file will be dragged

4) Resize Explorer window so that drop location is visible

5) Create a Device Replay object

6) Select files to be dragged

7) Drag & Drop file into the application

8) Close Explorer
 

Code:

'1) Identy the Object where the file to be dropped
Set oDesc = Description.Create
oDesc( "micclass" ).Value = "Frame"
set owinobject = Browser(browser_name).Page(page_name).ChildObjects(oDesc)

'2) Read x & y location of the Object'
        iXpos = oWinObject(0).getroproperty("abs_x")
        iYpos = oWinObject(0).getroproperty("abs_y")

'3) Open the folder in explorer from where file will be dragged
   SystemUtil.Run "C:\Temp","","","explore"

'4) Resize Explorer window so that drop location is visible   
    Window("Explorer").Resize 600,700
    Window("Explorer").Move 0,0
   
'5) Create a Devide Replay object
     Set devRep = CreateObject( "Mercury.DeviceReplay" )

'6) Select files to be dragged'
     Window("Explorer").WinListView("SysListView32").Select  "Test1.txt"
     Window("Explorer").WinListView("SysListView32").ExtendSelect  "Test2.txt"
   
'7) Drag and Drop the files into application'
    Set ctlr = DotNetFactory.CreateInstance("System.Windows.Forms.Control")
    devRep.DragAndDrop ctlr.MousePosition.X+10, ctlr.MousePosition.Y+1,iXpos +10,iYpos + 10,0
    
'8) Close Explorer'    
    Window("Explorer").Close