from selenium import webdriver
driver = webdriver.Chrome()
driver.get('C:/Users/yyh/Desktop/a.html')
js = """
(function(){
var canvas = document.getElementsByTagName("canvas", document).iterateNext();
console.log(canvas);
function getLocation(x, y) {
var bbox = canvas.getBoundingClientRect();
return {
x: (x - bbox.left) (canvas.width / bbox.width),
y: (y - bbox.top) * (canvas.height / bbox.height)
};
}
canvas.onmousedown = function (e) {
var location = getLocation(e.clientX, e.clientY);
console.log(location.x);
console.log(location.y);
<span>alert</span>("x=" + location.x + " ,y=" + location.y);
};
})
"""
driver.execute_script(js)