Javascript 使用webdriver.io拖放

Javascript 使用webdriver.io拖放,javascript,typescript,selenium-webdriver,selenium-chromedriver,wdio-v5,Javascript,Typescript,Selenium Webdriver,Selenium Chromedriver,Wdio V5,我正在尝试使用WebDriver.io的拖放方法,但它不起作用。我在网站上使用了拖放示例: 我需要一个角度应用程序的拖放功能的自动化 有人可以帮助我或找到解决方法。您可以使用buttonDown和buttonUp方法创建自定义拖放: dragAndDrop(element, x = 0, y = 0) { element.moveTo(); browser.buttonDown(0); element.moveTo(x, y); browser.buttonUp(0); } 您

我正在尝试使用WebDriver.io的拖放方法,但它不起作用。我在网站上使用了拖放示例: 我需要一个角度应用程序的拖放功能的自动化


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

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

dragAndDrop(element, x = 0, y = 0) {
  element.moveTo();
  browser.buttonDown(0);
  element.moveTo(x, y);
  browser.buttonUp(0);
}
您可以使用
otherElement.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 },
      ],
    },
  ]);
};