您可以使用 buttonDown 和 buttonUp 方法创建自定义拖放:
dragAndDrop(element, x = 0, y = 0) {
element.moveTo();
browser.buttonDown(0);
element.moveTo(x, y);
browser.buttonUp(0);
}
您可以使用otherElement.moveTo(); insted of element.moveTo(x, y); 来移动到特定元素。
你也可以使用performActions()函数,像这样:
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 },
],
},
]);
};