Forum Discussion

anapao's avatar
anapao
Occasional Contributor
4 years ago
Solved

Object cannot be recognized again once it has been clicked

Hi everybody,

 

I have an object that is not mapped automatically and therefore I have to work with it as an ImageRepositoryObject.

 

I want to drag the object. To extract the coordinates, I click on it.

 

Afterwards, when trying to drag it, the object is not recognized anymore. In the Script Test Log appears "unable to simulate the Drag action. No image was found". 

 

I do know that the click action is being succesfull because I get the right coordinates.

 

Any idea what is happening and how I could fix it? I would be very thankful! 

Here the code in case it helps:

ImageRepository.AssetLibraryMenus.Menu_ExternalEnergyNetworks.Click()

MySourceObject = ImageRepository.Assets.ElectricGridConnection
ImageRepository.Assets.ElectricGridConnection.Click()
SX = Sys.Desktop.MouseX
SY = Sys.Desktop.MouseY

MyDestinationObject = Aliases.ComponentTreeView.qt_scrollarea_viewport
MyDestinationObject.Click()
DX = Sys.Desktop.MouseX
DY = Sys.Desktop.MouseY

 

MySourceObject.Drag(SX,SY,DX, DY)


Best, 
Paola

  • Hi Paola,

     

    I do know that the click action is being succesfull because I get the right coordinates.

    a) Is there any chance that object is regenerated after click? If it is, then this may explain the error message, because your code does not search for the object before dragging but uses stored reference to it. And if the object is regenerated this invalidates the stored reference.

    You may try to replace .Click() call with the .HoverMouse() one. This should return same coordinates but should not cause any object regeneration (if any);

    b) Your code for drag seems to be incorrect. It uses absolute screen coordinates (e.g. Sys.Desktop.MouseX) while, as per documentation, the .Drag() method uses object-relative coordinates for drag start and not the final point but distance to drag for end. See method's description and code sample for more details.

     

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Paola,

     

    I do know that the click action is being succesfull because I get the right coordinates.

    a) Is there any chance that object is regenerated after click? If it is, then this may explain the error message, because your code does not search for the object before dragging but uses stored reference to it. And if the object is regenerated this invalidates the stored reference.

    You may try to replace .Click() call with the .HoverMouse() one. This should return same coordinates but should not cause any object regeneration (if any);

    b) Your code for drag seems to be incorrect. It uses absolute screen coordinates (e.g. Sys.Desktop.MouseX) while, as per documentation, the .Drag() method uses object-relative coordinates for drag start and not the final point but distance to drag for end. See method's description and code sample for more details.