vbscriptsap-gui

Select an item by name instead of id in VBS


I have recorded a script on SAP that runs on CITRIX. Everything worked fine until some items were added to the window that the right item was selected to filter the columns. I guess the reason is that the proper item (e.g. MATART in the shown picture) moved down and it was not the same row, order etc.

I was wondering whether there is a way to select the item by its name instead of id?

enter image description here

This is the part of the script with the line which selects the items:

session.findById("wnd[0]/tbar[0]/okcd").text = "/nzm082"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[33]").press
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellRow = 1
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/tbar[1]/btn[45]").press

Solution

  • You could test the following.

    for example:

    ...
    session.findById("wnd[0]/tbar[1]/btn[33]").press
    set myLayout = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell")
    
    Rows = myLayout.RowCount
    For i = 0 to Rows - 1 
    myVariant = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").getCellValue (i, "VARIANT")
    if myVariant = "MTART" then
       session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellRow = i
       session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").clickCurrentCell
       Exit For
    end if
    next
    session.findById("wnd[0]/tbar[1]/btn[45]").press
    ...
    

    Regards, ScriptMan