gpt4 book ai didi

javascript - 使用 webdriver.io 进行拖放

转载 作者:行者123 更新时间:2023-11-28 03:08:27 24 4
gpt4 key购买 nike

我正在尝试使用 WebDriver.io 的拖放方法,但它不起作用。我在网站上使用了拖放示例:https://www.w3schools.com/html/html5_draganddrop.asp我需要这个来自动化 Angular 应用程序的拖放功能。

有人可以帮助我或找到解决方法吗?

最佳答案

您可以使用buttonDown和buttonUp方法创建自定义拖放:

dragAndDrop(element, x = 0, y = 0) {
element.moveTo();
browser.buttonDown(0);
element.moveTo(x, y);
browser.buttonUp(0);
}

您可以使用 otherElement.moveTo(); 代替 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 },
],
},
]);
};

关于javascript - 使用 webdriver.io 进行拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60378820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com