Forum Discussion

sonali_suhani's avatar
sonali_suhani
Occasional Contributor
12 years ago

Drag and drop method in Testcomplete

Hello,



I want help in my script. I am working on windows application using vbscript in testcomplete in non recording mode. I want to drag an item from one folder to another in treelist . I'm having trouble using the drag method. Please Help me solving my issue.

I'm attaching my screeshot of the application indicating the file to be dragged. 

Also , please tell me how to cross check whether the item was successfully dropped or not.



Thanks in advance.
  • Hi Sonali,



    I was facing this problem this problem too, and I created a script to solve that this way:


    1. Retrieve the dragged object (with a find method, for example)


    2. Retrieve the destination object (the same way)


    3. Calculate the difference between dragged and destination objects top and left:

      - dragX = dragged object width / 2

      - dragY = dragged object height / 2

      - destinationX = dragged object left + dragX - ( destination object left + destination object width / 2 )

      - destinationY = dragged object top + dragY - ( destionation object top + destination object height / 2 )


    4. Perform the drag and drop to these coordinates


    This should do the trick!
  • Hello Sonali,



    The fastest way to do that is to actually record the test case (as a script, not as a keyword) and see how Test Complete does that by itself. Then you can adapt it to your scripts.



    To check the results, you can check if the dragged item parent object is the folder. I don't know much about vbs, so I can't show you an example. In JavaScript it would be something like that:



    theItem.Parent.wText == <FOLDER_NAME>



    I hope it helped!
  • sonali_suhani's avatar
    sonali_suhani
    Occasional Contributor
    Hi Javier,



    Thanks for the quick reply. I've already tried the record option. But in that case , its using the Drag() Method in which the position , i.e., X and Y coordinates of the dragging object and the destination folder's  X,Y coordinates are mentioned .

    But i cannot use the position thing as thisa position might get changed in the new build.

    So, i need some other way.

    Please suggest me any .

    Thanks