单击量角器中元素的给定坐标 [英] Clicking on given coordinates of element in protractor

查看:59
本文介绍了单击量角器中元素的给定坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想点击我的 canvas 元素的特定位置,所以我编写了以下量角器代码:

I want to click on a specific location of my canvas element, so I wrote the following Protractor code:

var canvas = element(by.id("canvas"));

var clickCanvas = function(toRight, toBottom) { 
  browser.actions()
    .mouseMove(canvas, -toRight, -toBottom)
    .click();
}

toRight/toBottom 是应该进行点击的像素数,相对于画布的左上角.

toRight/toBottom are the numbers of pixels where the click should be made, relative the top left corner of my canvas.

然而,点击似乎没有在给定的坐标处执行.我从 相关问题中得到了片段 关于软件质量保证测试堆栈交换.

However, the click does not seem to be executed at the given coordinates. I got the snippet from a related question on the Software Quality Assurance & Testing stack exchange.

你能确认这个片段有效吗?
你能提出替代方案吗?

Can you confirm that this snippet works?
Can you suggest alternatives?

推荐答案

我做了这个工作,传递一个表示坐标的对象作为 mouseMove 的第二个参数:

I made this work, passing an object representing the coordinate as the second argument of mouseMove:

var canvas = element(by.id("canvas"));

var clickCanvas = function (toRight, toBottom) { 
    browser.actions()
      .mouseMove(canvas, {x: toRight, y: toBottom})
      .click()
      .perform();
};

这篇关于单击量角器中元素的给定坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆