【发布时间】:2021-06-09 08:08:41
【问题描述】:
我不懂js,我是用python写的,但是我需要在网页上点击的位置画圆圈。所以,因为我真的使用硒,我需要看看点击在哪里。因为我不点击dom元素,所以点击坐标有时Selenium点击错误,所以想控制一下。 我尝试了一些类似下面的代码,当然它不起作用,我不知道为什么。所以我找到了similar solution。它对我不起作用。所以我找不到突出显示点击的有效解决方案。
var canv = document.createElement('canvas');
canv.id = 'canvas';
document.body.appendChild(canv);
document.getElementById('canvas').appendChild(canv);
onclick = function showCoords(event) {
var x = event.clientX;
var y = event.clientY;
var radius = 5;
var canvas = document.getElementsByTagName('canvas');
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.arc(x, y, radius, 40, 0, 2 * Math.PI);
ctx.stroke();
var coords = 'X coords: ' + x + ', Y coords: ' + y;
console.log(coords);
}
【问题讨论】:
标签: javascript selenium onclick highlight