python 与SAP GUI脚本的第二个选项卡交互

14ifxucb  于 2023-01-08  发布在  Python
关注(0)|答案(2)|浏览(187)

我正在创建一个脚本,我需要与第二个sap标签(红色)交互。当我使用第二个屏幕生成日志时,它会继续在第一个屏幕上播放(绿色)。我希望同时与多个标签交互。为此,我需要在代码中更改什么?
下面是通过在第二个选项卡中再现获得的代码示例

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "va03"
session.findById("wnd[0]").sendVKey 0

zzwlnbp8

zzwlnbp81#

也许你可以用这种方式循环不同的会话:

' Cycle through the open SAP GUI sessions and check which is in the same 
' system running the matching transaction
For il = 0 To application.Connections.Count - 1
    Set W_conn = application.Connections(il + 0)
    For it = 0 To W_conn.Sessions.Count - 1
        Set W_Sess = W_conn.Sessions(it + 0)
        If W_Sess.Info.SystemName = "NPL" Then
            Set objConn = W_conn
            Set objSess = W_Sess
            Exit For
        End If
    Next
Next

有关属性和方法的详细信息,请参阅文档:

6mzjoqzu

6mzjoqzu2#

import win32com.client

SapGuiAuto = win32com.client.GetObject("SAPGUI")
application = SapGuiAuto.GetScriptingEngine
connection = application.Children(0)
session = connection.Children(0)

session.findById("wnd[0]").maximize()
session.findById("wnd[0]/tbar[0]/okcd").text = "VA03"
session.findById("wnd[0]").sendVKey(0)


SapGuiAuto = win32com.client.GetObject("SAPGUI")
application= SapGuiAuto.GetScriptingEngine
connection = application.Children(0)
session2 = connection.Children(1)

session2.findById("wnd[0]").maximize()
session2.findById("wnd[0]/tbar[0]/okcd").text = "BD84"
session2.findById("wnd[0]").sendVKey(0)

相关问题