当前位置:网站首页>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);
边栏推荐
- MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?
- Tencent music knowledge map search practice
- OLED driven learning based on ssd1306 (II): addressing mode of ssd1306
- Volatile qualifier
- Openocd adds third-party device support: ht32f52352 Cortex-M0+
- Bank digital transformation layout in the beginning of the year, 6 challenges faced by financial level structure and Countermeasures
- Idea implements hot deployment
- Analysis and cleaning of kdevtmpfsi virus content
- Soft test intermediate simple notes
- Cvpr2020 | the latest cvpr2020 papers are the first to see, with all download links attached!
猜你喜欢

Decryption of APP parameters of a cross-border export e-commerce - dunhuang.com

05 configuring network parameters

Xshell mouse configuration

1.0-mq getting started and using

Soft test intermediate simple notes

1.1-mq visual client preliminary practice

Alicloud disk mounted locally

Get parameters in URL

Using two stacks to realize the function of one queue?

Cvpr2019 | the latest cvpr2019 papers are the first to read!
随机推荐
Is flush app regular? Is it safe or not
MySQL trigger
Write a "standard" macro min, which inputs two parameters and returns the smaller one
Shell scripts: Variables
Illustration tcp/ip - Chapter 1 and 2 Notes
Mysqldumpslow out slow statements in the database
Renren mall locates the file according to the route
Finger collar pin exclusive Medal
Nine built-in objects of JSP and four scopes of Servlet
Docker failed to remotely access 3306 after installing MySQL
Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection
The beginning of manjaro's journey
Is it safe to fry stocks with compass or securities software? Where can I open an account and how
Docker Alpine image installation PHP extension redis
C language: array with length 0
C language dynamic memory allocation
Illustrated with pictures and texts, 700 pages of machine learning notes are popular! Worth learning
Nmap is simple and practical
Insert and update each database
MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?