如何使用Protractor/Selenium将鼠标移动到任意点

And*_*ndy 18 javascript selenium point mousemove protractor

是否可以将鼠标移动到屏幕上的任意坐标/相对于量角器测试中的元素?我看到人们推荐使用Robot for Java用户,但当然我不能在JavaScript中使用它.

And*_*ndy 32

我自己想出来......只是通过Protractor和Selenium文档深入挖掘.这是一些示例代码:

  it('should pan plots when you click and drag', function() {
    var plot0 = element(by.css('.plot > canvas'));
    browser.actions()
      .mouseMove(plot0, {x: 100, y: 100}) // 100px from left, 100 px from top of plot0
      .mouseDown()
      .mouseMove({x: 400, y: 0}) // 400px to the right of current location
      .perform();
  });
Run Code Online (Sandbox Code Playgroud)