js获取元素的坐标
js_code = """
function getRect(elements) {
var rect = elements.getBoundingClientRect();
w = rect.width || rect.right - rect.left;
h = rect.height || rect.bottom - rect.top;
ww = document.documentElement.clientWidth;
hh = document.documentElement.clientHeight;
return {
top: (window.outerHeight - window.innerHeight) + Math.floor(rect.top),
bottom: Math.floor(hh - rect.bottom),
left: Math.floor(rect.left),
right: Math.floor(ww - rect.right),
width: ww,
height: hh,
elem_width: rect.width,
elem_height: rect.height
};
};
var box = arguments[0];
var obj = getRect(box);
var str = obj.top + '|' + obj.left + '|' + obj.bottom + '|' + obj.right + '|' + obj.width + '|' + obj.height;
return obj
"""
el = driver.find_element_by_xpath(xpath)
res = driver.execute_script(js_code, el) # 坐标就可以获取到了
说的再好,不如行动。不怕慢,就怕站。

浙公网安备 33010602011771号