Hello André,
welcome in the Scripting Language forum.
Here an example how to solve your problem:
'-Begin-----------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Function getSimpleContainer-----------------------------------------
Function getSimpleContainer(session)
'-Variables-------------------------------------------------------
Dim SimpleContainer
On Error Resume Next
Set SimpleContainer = session.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013")
If Not IsObject(SimpleContainer) Then
Set SimpleContainer = session.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0016")
End If
On Error Goto 0
Set getSimpleContainer = SimpleContainer
End Function
'-Sub Main------------------------------------------------------------
Sub Main()
'-Variables-------------------------------------------------------
Dim SapGuiAuto, application, connection, session
Dim SimpleContainer, btnHeader, btnItemOver, btnItem
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
Set SimpleContainer = getSimpleContainer(session)
Set btnHeader = session.FindById(SimpleContainer.ID & _
"/subSUB1:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4000/btnDYN_4000-BUTTON")
If btnHeader.IconName = "DAAREX" Then
btnHeader.press
End If
Set SimpleContainer = getSimpleContainer(session)
Set btnItemOver = session.FindById(SimpleContainer.ID & _
"/subSUB2:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4001/btnDYN_4000-BUTTON")
If btnItemOver.IconName = "DAAREX" Then
btnItemOver.press
End If
Set SimpleContainer = getSimpleContainer(session)
Set btnItem = session.FindById(SimpleContainer.ID & _
"/subSUB3:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4002/btnDYN_4000-BUTTON")
If btnItem.IconName = "DAAREX" Then
btnItem.press
End If
End Sub
'-Main----------------------------------------------------------------
Main
'-End-------------------------------------------------------------------
I get the status of the button via the icon in the button, it differs whether it is open or closed.
With each button press the simple container, which containes all elements, changes its ID. So is it necessary to detect the name of the simple container after each button press.
Let us know your results.
Cheers
Stefan