我想点击我的 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(); };更多推荐
单击量角器中元素的给定坐标
发布评论