赞
踩
目录
Scripting Tracker SAP脚本录制工具是 SAP ® GUI 脚本开发工具的替代品,和SAP自带的脚本录制功能一样,都是记录操作脚本,Scripting Tracker可以转换成c#,java,Python等脚本代码
Scripting Tracker 下载地址:https://tracker.stschnell.de/
下载解压安装包后打开Scripting Tracker ,直接点击刷新就能自动检测到SAP,(前提是要打开SAP GUI 界面,点击刷新的时候才能连接成功,打开几个窗口,刷新的时候就能检测导几个)
连接上之后,点击开始录制,Scripting Tracker就会把你的每一步操作都i记录下来,同时翻译成对应的脚本语言,是直接可以用的,如果没反应点击结束录制,多试几次就行
Python要连接SAP,需要Python安装win32com组件,有了它,就可以通过Python来连接本地的win32程序并通过捕获相应句柄来控制对应的窗口
官方下载地址:pywin32 224
- #-Begin-----------------------------------------------------------------
-
- #-Includes--------------------------------------------------------------
- import sys, win32com.client
- import win32api,win32gui,win32con,win32ui,time,os,subprocess
-
- #-Sub Main--------------------------------------------------------------
- def Main():
- sap_app = r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe" #您的saplogon程序本地完整路径
- subprocess.Popen(sap_app)
- time.sleep(1)
- flt=0
- while flt==0:
- try:
- hwnd = win32gui.FindWindow(None,"SAP Logon 740")
- flt=win32gui.FindWindowEx(hwnd,None,"Edit", None) #capture handle of filter
- except:
- time.sleep(0.5)
- win32gui.SendMessage(flt,win32con.WM_SETTEXT,None,"S4 DEV")
- win32gui.SendMessage(flt,win32con.WM_KEYDOWN,win32con.VK_RIGHT,0)
- win32gui.SendMessage(flt,win32con.WM_KEYUP,win32con.VK_RIGHT,0)
- time.sleep(0.1)
-
- dlg = win32gui.FindWindowEx(hwnd,None,"Button", None) #登陆(0)
- win32gui.SendMessage(dlg,win32con.WM_LBUTTONDOWN,0)
- win32gui.SendMessage(dlg,win32con.WM_LBUTTONUP,0)
-
- SapGuiAuto = win32com.client.GetObject("SAPGUI")
- if not type(SapGuiAuto) == win32com.client.CDispatch:
- return
-
- application = SapGuiAuto.GetScriptingEngine
- if not type(application) == win32com.client.CDispatch:
- SapGuiAuto = None
- return
-
- connection = application.Children(0)
- if not type(connection) == win32com.client.CDispatch:
- application = None
- SapGuiAuto = None
- return
- time.sleep(2)
-
- flag=0
- while flag==0:
- try:
- session = connection.Children(0)
- flag=1
- except:
- time.sleep(0.5)
-
- if not type(session) == win32com.client.CDispatch:
- connection = None
- application = None
- SapGuiAuto = None
- return
- session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "user" #SAP登陆用户名
- session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "pass" #SAP登陆密码
- session.findById("wnd[0]").sendVKey(0)
-
- #打开自开发的一个扫雷游戏tcode,直接插入录制的脚本
- session.findById("wnd[0]").resizeWorkingPane(155, 34, 0)
- session.findById("wnd[0]/tbar[0]/okcd").text = "ZSL"
- session.findById("wnd[0]").sendVKey(0)
- session.findById("wnd[0]/usr/btnHIGH").press()
- session.findById("wnd[0]/usr/btnSTART").press()
- #>Insert your SAP GUI Scripting code here<
-
- #-Main------------------------------------------------------------------
- if __name__ == "__main__":
- Main()
-
- #-End-------------------------------------------------------------------
运行代码查看效果。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。