Tuesday, August 24, 2010

Test Complete script to drag and drop an object (Vb Script)

This script can be used to drag and drop an object from one screen to another screen without using the coordinates.Everyobject has Left,Top ,width, ScreenLeft ,ScreenTop properties.

These properties can be used to achieve the drag and drop .

This was written with the help of Jay , AutomatedQA while trying to move an object from one screen to another
.
Sub DragAndDropItems(ReqObjectToMove,DestControl)
Dim XPos ,YPos ,dX ,dY
LogFolder = Log.CreateFolder("Draging and dropping item ")
Log.PushLogFolder(LogFolder)


XPos = ReqObjectToMove.Left+ReqObjectToMove.Width/2
YPos = ReqObjectToMove.Top+ReqObjectToMove.Height/2


dX = DestControl.ScreenLeft - ReqObjectToMove.ScreenLeft
dY = DestControl.ScreenTop - ReqObjectToMove.ScreenTop


Call ReqObjectToMove.Drag(XPos, YPos, dX, dY)
Log.PopLogFolder


End Sub
 
If your object does not have a Drag method ,alternative method is to drag an object to the desired position is to use LLPlayer to simulate the drag operation.

No comments:

Post a Comment