TestComplete: when method Drag doesn't work
@ Mo, 22 December 2008, 11:14Sometimes code recorded by TestComplete does not replay as it is expected. One of the problem methods is Drag() method, which allows to move objects to other positions. In this case we can use methods MouseDown() and MouseUp() of Sys.Desktop object to create own dragging function.
function DragDrop(obj, deltaX, deltaY)
{
var iX = obj.ScreenLeft + obj.Width/2;
var iY = obj.ScreenTop + obj.Height/2;
Log.Picture(obj.Picture(), "Object to be moved");
obj = Sys.Desktop.ObjectFromPoint(iX + deltaX, iY + deltaY);
Sys.Desktop.MouseDown(VK_LBUTTON, iX, iY);
obj.HoverMouse(obj.Width/2, obj.Height/2);
Sys.Desktop.MouseUp(VK_LBUTTON, iX + deltaX, iY + deltaY);
}
This function presses left mouse button in the center of the object to be moved, then moves mouse cursor to the new destination and releases pressed button. Here is an example demonstrating moving of icons in the QuickLaunch toolbar.
function Test3()
{
var w1 = Sys.Process("Explorer").Window("Shell_TrayWnd").Window("ToolbarWindow32", "Quick Launch");
DragDrop(w1, -30, -20);
}
