Forum Discussion

asavoia's avatar
asavoia
Occasional Contributor
4 years ago
Solved

problem with a drag command

hi everyone, I have a problem with the drag command. since I don't want to use coordinates, is it possible to use drag in some alternative method? I don't want to use the coordinates because I woul...
  • tristaanogre's avatar
    tristaanogre
    4 years ago

    The drag command in testcomplete needs co-ordinates.  You need to know the object to be dragged and the destination and that is, for the Drag method, co-ordinate based.

     

    but!  Never fear... I've got a code for that.

     

    In Javascript:

     

    function dragCalculatedDistance(startObject, destinationObject) {
        var startPoint, targetPoint, dragX, dragY;
        // Drag from the center of object A to the center of object B
    
        startPoint = startObject.WindowToScreen(startObject.Width/2, startObject.Height/2);
        targetPoint = destinationObject.WindowToScreen(destinationObject.Width/2, destinationObject.Height/2);
    
        dragX = targetPoint.X - startPoint.X;
        dragY = targetPoint.Y - startPoint.Y;
    
        startObject.Drag(-1, -1, dragX, dragY); 
    }

    As noted in the comments, this will drag from roughly the center of the starting object to the center of the destination object.