当前位置:网站首页>The robotframework executes JS commands to move the mouse from X to y
The robotframework executes JS commands to move the mouse from X to y
2022-06-25 21:20:00 【Strange meow】
Use keywords :Execute Javascript
js Interface to realize mouse from x Point to move to y spot , The time interval is n:
function createMouseEvent(type) {
return function (x, y) {
var ev = document.createEvent("MouseEvent");
ev.initMouseEvent(
type,
true /* bubble */,
true /* cancelable */,
window,
1,
0,
0,
x,
y /* coordinates */,
false,
false,
false,
false /* modifier keys */,
0 /*left*/,
null
);
document.dispatchEvent(ev);
};
}
const mousedown = createMouseEvent("mousedown");
const mousemove = createMouseEvent("mousemove");
const mouseup = createMouseEvent("mouseup");
async function sleep(time) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, time);
});
}
const INTERVAL = 20;
async function mockOperation(startX, startY, endX, endY, time) {
mousedown(startX, startY);
const count = Math.ceil(time / INTERVAL);
const offsetX = (endX - startX) / count;
const offsetY = (endY - startY) / count;
for (let i = count; i > 0; i--) {
mousemove(endX - offsetX * i, endY - offsetY * i);
await sleep(INTERVAL);
}
mouseup(endX, endY);
}
await mockOperation(100, 100, 500, 500, 2000);
边栏推荐
- Must see the summary! In depth learning era, you should read 10 articles to understand image classification!
- ThreadLocal class
- Unable to connect to the server remotely locally using the Jupiter notebook
- Mutual conversion of CString and char*
- CANoe. Diva operation guide TP layer test
- JVM Foundation
- Lesson 1 Preparation
- Kubernetes related knowledge - surprise interview
- 启牛学堂证券开户安全嘛?
- 2022年启牛学堂证券开户安全嘛?
猜你喜欢

109 practical shell scripts

Finger collar pin exclusive Medal

Yolov4 improved version comes out! Yolov4 extended edition! Yolov4 launched scaled-yolov4: scaling cross stage partial network

Sqlmap for interface security testing
![[nailing scenario capability package] smart office phone](/img/ec/c2f342a54ab69d8b834a8a1c8f8a01.jpg)
[nailing scenario capability package] smart office phone

1.0-mq getting started and using

Free your hands and automatically brush Tiktok

Mutual conversion of CString and char*

js (1)

The beginning of manjaro's journey
随机推荐
Docker Alpine image installation PHP extension redis
Free your hands and automatically brush Tiktok
Kubernetes related knowledge - surprise interview
Virtualenvwrapper solves the installation error, and virtualenvwrapper is permanently effective
Get parameters in URL
Getting started and using postman
The super easy-to-use test tool sorted out by Ali P8 for a week
Summary of several methods for FPS calculation
Finger collar pin exclusive Medal
JS__ This, arguments, cloning, ternary operator__ Duyi
New generation engineers teach you how to play with alluxio + ml (Part 2)
Openocd compilation and installation
ThreadLocal class
Yunzhisheng atlas supercomputing platform: computing acceleration practice based on fluid + alluxio (Part I)
Lesson 1 Preparation
Jmeter- (II) basic interface and common components for interface testing
The difference between strcpy and memcpy
Openocd adds third-party device support: ht32f52352 Cortex-M0+
The user name and password will be automatically filled in when adding a form
XMIND to excel test case