Application

Drag and Drop

DragAndDrop reads the selectors in the current unit of work. Two selectors name the two ends: the first is grabbed and released over the second, with the distance worked out from where the two elements actually are, so the workflow never counts pixels and the drag survives a resized window or a re-sorted list. One selector means a distance instead, taken from that selector's DeltaX and DeltaY, which is what a drag means when the destination is not an element: a slider, a splitter, a rubber band. The element is taken hold of at its middle unless the selector gives an offset, and the target is dropped on at its middle unless its selector does. A modifier key can be held for the length of the drag.

NOTE

Dragging several things is not something GPAL does differently. Selection is the application's idea, so the workflow builds it with clicks the way a person does, a click then shift clicks for a range or control clicks for a set, and then drags from any selected element. Whatever is selected comes along. A drag is always input layer: UIAutomation has no pattern that expresses one, on any control, in any application. So a drag moves the real pointer, and cannot run on a desktop that is not receiving input.

Examples

GPAL Fluent: High-level fluent C# API

//The drag presses, travels and releases, and the travel is what makes it a drag: Windows starts one only when the pointer moves past its drag threshold while the button is held, and only if it sees the movement. GPAL.WithSimulateMouseMovement decides whether the pointer wanders there the way a hand would or steps clear of the threshold and jumps. A held modifier is released whatever happens in between, and a modifier left held by something else is released before the drag starts, because the shell reads the keyboard at the moment of the drop.

// drag one element onto another

myApplication

.WithSelector(fileRow)

.WithSelector(targetFolderRow)

.DragAndDrop();


// build a selection first, then drag it

myApplication

.WithSelector(firstRow)

.LeftClick()

.WithSelector(thirdRow)

.LeftClick(ModifierKeys.Shift)

.WithSelector(firstRow)

.WithSelector(targetFolderRow)

.DragAndDrop();


// a distance, for a destination that is not an element

Selector slider = (Selector)GPAL.Selector

.WithDeltaX(120)

.WithSelectorName("Slider")

.WithXPath("/Desktop/Window//Slider");


myApplication

.WithSelector(slider)

.DragAndDrop();

💬 Ask GPAL