方法:
通过javascript获取需要拖拽位置相对位置的x,y轴位置,python调用windows api操作鼠标拖拽,入参添加x,y轴的位置调整参数
具体实现:
- 通过javascript获取需要拖拽位置相对位置的x,y轴位置
- 编写python调用windows api操作鼠标拖拽方法
- Robot Framework RIDE 调用关键字
代码
import win32api
def mouse_drafting(self,from_xOffset, from_yOffset, to_xOffset, to_yOffset):
'''
功能: 通过鼠标拖拽移动位置
参数说明:
作者: XXX
日期: 20190118
更新记录:
'''
#定位位置
win32api.SetCursorPos((int(from_xOffset), int(from_yOffset)))
time.sleep(1)
#按下鼠标左键
win32api.mouse_event(2, int(from_xOffset), int(from_yOffset))
time.sleep(0.5)
#移动鼠标位置
win32api.mouse_event(1, int(to_xOffset), int(to_yOffset))
time.sleep(0.5)
#松开鼠标左键
win32api.mouse_event(4, 0, 0)
time.sleep(0.5)
RIDE代码:
${x_left} Selenium2library.Execute JavaScript return (function(){var odiv=document.getElementsByClassName(“list-container”);var x_left=odiv[0].getBoundingClientRect().left;return x_left;})()
${y_top} Selenium2library.Execute JavaScript return (function(){var odiv=document.getElementsByClassName(“list-container”);var y_top=odiv[0].getBoundingClientRect().top;return y_top;})()
mouse_drafting ${x_left}+准确位置偏移值 ${y_top}+准确位置偏移值 100 0
----------------如有疑问请加微信留言,xiuse_10000