cancel
Showing results for 
Search instead for 
Did you mean: 

python sap gui scripting event

748

Dear all.

We use python call sap gui scriping to do some rpa work, and it worked very well in majority associations,but when we use python to bind event of application , there is a problem .

The bellow code we tested in VBS and it runed well.

Dim objSapGui
Set objSapGui = GetObject("SAPGUI")

Dim objScriptingEngine
Set objScriptingEngine = objSapGui.GetScriptingEngine
WScript.ConnectObject objScriptingEngine, "Engine_"

Dim Waiting
Waiting = 1

Do While (Waiting = 1)
WScript.Sleep(100)
Loop

Set objScriptingEngine = Nothing
Set objSapGui = Nothing

Sub Engine_CreateSession(ByVal Session)
Dim result
result = MsgBox("Session created", vbOKCancel)
If result = vbCancel then
Waiting = 0
End If
End Sub


But when we ran bellow code in python, there turned up with an error: AssertionError

assert enumEntry.desc.desckind == pythoncom.DESCKIND_FUNCDESC

import win32com.client 

class Events:
def __init__(self):
pass

appl = win32com.client.GetObject("SAPGUI").GetScriptingEngine
event = win32com.client.WithEvents(appl, Events)

I have tested that win32com.client.WithEvents by Excel and it runs well.

excel = win32com.client.Dispatch("Excel.Application")
win32com.client.WithEvents(excel, SessionEvents)


Do you have any successful example aboout binding sap gui scripting event by python?


Thanks!

Accepted Solutions (0)

Answers (0)