javascript - 通过 Repeater 使用 Protractor 拖放

标签 javascript drag-and-drop repeater protractor

有几个问题和这个类似,我都看完了。但是,我仍然无法让 Action Sequence 在 Protractor 中按预期工作。

我有一个可拖动的项目列表,我需要在重新排列后测试结果。但是我无法让拖放操作正常工作。这是我目前所拥有内容的简化模型。

辅助函数:

var getRow = function (num){
      return element(by.repeater('p in pList').row(num - 1));
};

var getField = function (rowNum){
    return getRow(rowNum).findElement(by.css('td.ng-binding'));
};

var moveIndexToIndex = function (startIndex, endIndex) { 
  return getField(endIndex).then(function (endPoint) {
      getField(startIndex).then(function (startPoint) { 
          // browser.actions().dragAndDrop(startPoint, endPoint).perform(); // doesn't work either
          browser.actions().
            mouseMove(startPoint, {x: 0, y: 0}).
            mouseDown().
            mouseMove(endPoint).
            mouseUp().
            perform();   
      });
    });
});

我用这样的文字调用移动辅助函数:

moveIndexToIndex(2, 5);

html 看起来像这样:

<tbody>
          <!-- ngRepeat: p in pList -->
          <tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 1</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 2</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 3</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 4</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 5</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 6</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 7</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 8</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 9</td>
          </tr><!-- end ngRepeat: p in pList --><tr ng-repeat="p in pList" eg-draggable="p" eg-droppable="eg-droppable" class="ng-scope" draggable="true" style="cursor: move;">
            <td class="ng-binding">DummyValue 10</td>
          </tr>
          <!-- end ngRepeat: p in pList -->
</tbody>

我怎样才能让拖放工作?我做错了什么吗?

最佳答案

通过对 Protractor 的更新更改修复了此问题。我缺少替换 .find() 方法的 .getWebElement() 部分。

browser.actions().
        mouseMove(startPoint.getWebElement(), {x: 0, y: 0}).
        mouseDown().
        mouseMove(endPoint.getWebElement()).
        mouseUp().
        perform(); 

关于javascript - 通过 Repeater 使用 Protractor 拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24315571/

相关文章:

javascript - 如何在 CSS 或内联中增加 SVG 路径的宽度

javascript - 使用 google api 时日期选择器不工作

javascript - 无需库帮助的简单 JavaScript 拖放

java - 使用 Java 为某种信使应用程序创建动态 JLabel

Dojo 1.7.2 拖放错误 - "mouseButtons.isLeft"

asp.net - 如何更改中继器中的列(数据集)值名称

asp.net - 在 Repeater 的 HeaderTemplate 中设置 MyLabel.Text

javascript - 将类添加到样式组件

c# - 中继器控件内的 IF 条件?

javascript - .NET Core Web API 中的 IFormFile 对于 axios 和 ajax 文件上传为 null,但在 Postman 中有效