首页 新闻 搜索 专区 学院

python selenium注入js失败,怎么修改才能注入成功呢?

0
悬赏园豆:50 [待解决问题]

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)

kun爱莫能助的主页 kun爱莫能助 | 初学一级 | 园豆:76
提问于:2020-01-07 14:10
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册