Drag an element from one place to another
To drag an element from the specified positionFrom to the specified positionTo, use the DragAndDrop() method from the PanelSimulator class.
The following example shows how to use the DragAndDrop function to drag on a slider:
[Test]
public void MouseDragExample()
{
// Make sure the UI is totally up to date.
simulate.FrameUpdate();
// Fetch and focus the Slider.
var slider = rootVisualElement.Q<Slider>("MySlider");
var dragger = slider.Q<VisualElement>("unity-dragger");
slider.Focus();
simulate.FrameUpdate();
Assume.That(dragger.ClassListContains("unity-base-slider--movable"));
Assume.That(slider.hasFocusPseudoState, Is.True);
var startingPosition = slider.value;
// Send RightArrow key presses.
simulate.DragAndDrop(dragger.worldBound.center,
dragger.worldBound.center + new Vector2(10, 10));
simulate.FrameUpdate();
var endingPosition = slider.value;
Assert.That(endingPosition, Is.GreaterThan(startingPosition),
"Slider value did not update as expected.");
}