If you want to create a personalized drag-and-drop feature, you can achieve this by using the buttonDown and buttonUp methods:
dragAndDrop(element, x = 0, y = 0) {
element.moveTo();
browser.buttonDown(0);
element.moveTo(x, y);
browser.buttonUp(0);
}
To move to a specific element, you can use otherElement.moveTo();
instead of element.moveTo(x, y);
.
Another option is to utilize the performActions()
function as shown below:
const dragAndDrop = (element, x = 0, y = 0) => {
const location = getElementLocation(element);
browser.performActions([
{
type: 'pointer',
id: 'finger1',
parameters: { pointerType: 'mouse' },
actions: [
{ type: 'pointerMove', duration: 0, x: location.x, y: location.y },
{ type: 'pointerDown', button: 0 },
{ type: 'pointerMove', duration: 0, x: location.x + x, y: location.y + y },
{ type: 'pointerUp', button: 0 },
],
},
]);
};