'SAP GUI Script, how to switch diffrent window
Sometimes, during automatic processing, sap is not completely closed, so there are some open windows. For example, the already open window ID is
/app/con[0]/ses[0]/wnd[0]
The newly opened window is / APP / con [1] / SES [0] / wnd [0]
.
Note: the value after con of the new window ID has changed.
In automation, I hope to automatically select the window that appears later. But this window can't use findbyid to find.
I tried to confirm the corresponding window by traversing the window title, but this error occurred: 'SAP frontend server', 'the control could not be found by ID.'
sample code:
SapGuiAuto = win32com.client.GetObject("SAPGUI")
application = SapGuiAuto.GetScriptingEngine
sleep(1)
connection = application.Children(0)
session = connection.Children(0)
# At this time, I have opened a window whose ID is '/app/con[0]/ses[0]/wnd[0]'
# However, the window ID automatically opened by the program is '/app/con[1]/ses[0]/wnd[0]', I need connect this window.
# get window’s title
title = session.findById('/app/con[1]/ses[0]/wnd[0]').Text
error occurred:
pywintypes.com_error: (-2147352567, 'Exception occured', (619, 'SAP Frontend Server', 'The control could not be found by id.', 'C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\sapfront.HLP', 393215, 0), None)
If I connect to sap with the following code:
text1 = session.findById("wnd[0]").Text
This will get the title of the window that has been opened long ago, such ascreate purchase requisition
rather than the title of the login page that the program opens: SAP
Solution 1:[1]
I´m using some SAP scripting automation from Excel VBA.
To select an session and correct window I´ve created an pulic function which fill an userform listbox:
Public function Session Listbox
If you can translate VBA to Python this may support you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Holger K |