Drag Action

Applies to TestComplete 15.10, last modified on December 15, 2021

Description

Use the Drag action to simulate a dragging event that is performed with the left mouse button over an onscreen object or window.

Declaration

TestObj.Drag(ClientX, ClientY, toX, toY, Shift)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
ClientX [in]    Required    Integer    
ClientY [in]    Required    Integer    
toX [in]    Required    Integer    
toY [in]    Required    Integer    
Shift [in]    Optional    TShiftKey Default value: skNoShift   
Result None

Applies To

All onscreen objects.

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameters:

ClientX

Specifies the horizontal coordinate of the start point for dragging. This coordinate is relative to the object, it is not a screen coordinate.

ClientY

Specifies the vertical coordinate of the start point for dragging. This coordinate is relative to the object, it is not a screen coordinate.

toX

Specifies the horizontal dragging distance in pixels.

toY

Specifies the vertical dragging distance in pixels.

Shift

Sets whether the Shift, Alt or Ctrl keys are pressed during the dragging event (see TShiftKey). By default, this parameter is skNoShift (no shift keys are pressed). Sometimes the Shift parameter may not be enough, and you may need to simulate key presses in script code. See Simulating Keystrokes.

Result Value

None.

Remarks

  • The Drag action works in the following manner:

    • Moves the mouse cursor to the point specified by the ClientX and ClientY parameters.

    • “Presses” the left mouse button.

    • “Holds” the button down and moves the cursor to the distance specified by the toX and toY parameters.

    • “Releases” the left mouse button.

  • Desktop testing: If TestObj refers to an object of a non-DPI-aware application running with a DPI setting other than 100%, set the ClientX, ClientY, toX and toY parameter values relative to the application (as if the application is running with the 100% DPI setting).

  • Web testing: If the Use CSS pixels for scaled pages option is enabled (by default), set the ClientX, ClientY, toX and toY parameter values relative to the web page, regardless of the browser zoom and the system's DPI setting.

  • In order to simulate dragging actions on Telerik RAD controls for Silverlight, increase the value of the Dragging delay project option (default value is 5 milliseconds, recommended value is 50 milliseconds or higher). Otherwise the dragging actions may not be simulated correctly.

Example

The following example demonstrates how to use the Drag action in scripts:

JavaScript, JScript

var p, w;
p = Sys.Process("notepad");
w = p.Window("Notepad", "Untitled - Notepad", 0);
w = w.Window("Edit", "", 0);
w.Drag(30, 40, 50, 0);

Python

p = Sys.Process("notepad")
w = p.Window("Notepad", "Untitled - Notepad", 0)
w = w.Window("Edit", "", 0)
w.Drag(30, 40, 50, 0)

VBScript

Set p = Sys.Process("notepad")
Set w = p.Window("Notepad", "Untitled - Notepad", 0)
Set w = w.Window("Edit", "", 0)
w.Drag 30, 40, 50, 0

DelphiScript

var
  p, w : OleVariant;
begin
  p := Sys.Process('notepad');
  w := p.Window('Notepad', 'Untitled - Notepad', 0);
  w := w.Window('Edit', '', 0);
  w.Drag(30, 40, 50, 0);
end;

C++Script, C#Script

var p, w;
p = Sys["Process"]("notepad");
w = p["Window"]("Notepad", "Untitled - Notepad", 0);
w = w["Window"]("Edit", "", 0);
w["Drag"](30, 40, 50, 0);

See Also

Simulating User Actions
DragM Action
DragR Action
Click Action
DblClick Action
MouseDown Method (Desktop Objects)
MouseUp Method (Desktop Objects)

Highlight search results