cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sap gui scripting issue with Python

SAPSupport
Employee
Employee
0 Likes
2,309

Dear Expert,

We use python call SAP GUI scripting to do some RPA work, and it worked very well in majority associations, but when we use python to bind event of application , there have a problem and we can't solve by ourselves, could you help us to determine is there any bug in SAP GUI scripting with python?

The bellow code we tested in VBS and it run 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
import win32com.client

class Events:
def __init__(self):
pass

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

Looking forwar to your reply


Thanks!


------------------------------------------------------------------------------------------------------------------------------------------------
Learn more about the SAP Support user and program here.
View Entire Topic
SAPSupport
Employee
Employee

Hello customer,

Thank you for reaching out to SAP Community.

Please refer to the technical article available in the following link:

https://blogs.sap.com/2017/09/19/how-to-use-sap-gui-scripting-inside-python-programming-language/

The recorded VBScript code can use almost always unchanged inside Python, but sometimes it is necessary to set some brackets.

Try to use the sample code outlined in the blog.

Best regards,

SAP Support