Forum Discussion
Attached the Drag Operation.
I'm kind of guessing here, but I'm not sure about -1 as the Client X/Y co-ordinate?
I use drag and drop. To determine where I need to click (I always want the centre point), I get the Width and Height of the object to be dragged and divide those by two. Which gives me the centre point. The objects being dragged by my script can be of various different sizes, so I have to calculate the click point myself. (Of course, I also have to calculate the destination point as well. But that's a slightly different matter.)
I can't see how "-1" could be a valid value for this (as these co-ordinates represent a point within the object to be dragged so the top left corner should be 0,0). But it obviously allows it. But I'm not sure where -1,-1 will put the mouse pointer, and I didn't see anything in the Drag method documentation that tells you this either.
Or possibly HKosova may be able to tell us what it's doing with the -1's you currently have in there?
- HKosova9 years ago
Alumni
In all mouse operations (Click, Drag, HoverMouse, etc.) -1,-1 means the object's center point. So in your example the dragging should start at the center of the PM.PMShell.ListViewItem object.
Does this ListViewItem point to the same object in both scenarios? To check that, add Log Message before the drag and log the ListViewItem's FullName property (set the MessageText parameter to the Object Property mode, then pick the object and property).
- Colin_McCrae9 years agoCommunity Hero
HKosova .... that's handy to know. I didn't realise that.
As I mentioned, I calculate the CenterPoint myself. Didn't realise I could have just used -1's!
- ashishnagpal269 years agoContributor
Hi Helen ,
Yes in both the scenarios it points to the same object .
The reason I am saying this is we are using drag and drop functionality so when I assumed that -1 , -1 is the center of the object I gave a horizontal drag point of 250 which was good enough for it to drop the object but when the test ran from the excel ( keyword ) scripts the same -1 , -1 was pointing to the left top corner of the object and the drag value of 250 wasn't good enough and it wasn't dropping the object.
When I increased the drag value from 250 to 600 it was successful.
- HKosova9 years ago
Alumni
ashishnagpal26 wrote:
When I increased the drag value from 250 to 600 it was successful.
On a related note, it's better to avoid hard-coded drag distance and calculate it dynamically based on the target object location. This can be done as follows:
// Drag from the center of object A to the center of object B
start_point = A.WindowToScreen(A.Width/2, A.Height/2); target_point = B.WindowToScreen(B.Width/2, B.Height/2);
dragX = target_point.X - start_point.X; dragY = target_point.Y - start_point.Y;
A.Drag(-1, -1, dragX, dragY);