问题描述
我创建了一个Python应用程序来运行SAP GUI的功能测试,但是我无法启动SAPGUI会话,我使用通过脚本跟踪器捕获的脚本,但这是在获得SAP会话之前发生的。
当我打开SAP logon时,会看到一个包含环境列表的窗口,在这里我可以从不同的服务器中选择要使用的窗口,通常,列表中的第一个环境就是我需要的环境,因此我只需要向Windows发送一个enter即可。打开SAP正常会话并开始进行身份验证。
窗口如下:
os.startfile("C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe")
shell = win32com.client.dispatch("WScript.Shell")
shell.SendKeys('{ENTER}')
然后我像这样创建一个SAP会话:
sapGuiAuto = win32com.client.Getobject("SAPGUI")
sapApplication = sapGuiAuto.GetScriptingEngine
time.sleep(1)
sapConnection = sapApplication.Children(0)
session = sapConnection.Children(0)
我一直在阅读一些有关com对象的信息,我认为我可以从一开始就使用win32com.client.Getobject(“ SAPGUI”),但我一直在尝试做类似的事情而没有成功:
测试1
sapGuiAuto = win32com.client.Getobject("SAPGUI")
sapGuiAuto.SendKeys('{ENTER}')
测试2
sapGuiAuto = win32com.client.Getobject("SAPGUI")
sapApplication = sapGuiAuto.GetScriptingEngine
time.sleep(1)
sapConnection = sapApplication.Children(0)
session = sapConnection.Children(0)
session.findById("wnd[0]").sendVKey(0)
是否有比使用win32com.client.dispatch(“ WScript.Shell”)更好的启动SAP GUI的方法? SAP logon是否具有不同的ProgId?
谢谢
解决方法
我不了解Python,但是您可以尝试以下操作:
'Here comes the full name of the connection from SAP Logon
myConnection = "DE2 [erpdd...]"
os.startfile("C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe")
shell = win32com.client.Dispatch("WScript.Shell")
time.sleep(4)
sapGuiAuto = win32com.client.GetObject("SAPGUI")
sapApplication = sapGuiAuto.GetScriptingEngine
sapConnection = sapApplication.openconnection(myConnection)
session = sapConnection.Children(0)
session.findById("wnd[0]").maximize
'start authenticating
...
关于ScriptMan,