Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Determining the item names and item texts of a SapContextMenu

Determining the item names and item texts of a SapContextMenu

When automating a SAP application, during which you must interact with a SapContextMenu, it is not possible to identify SapContextMenu controls or their menu items using the Locator Spy. This can make it difficult to determine what names and item texts have been associated with each SapContextMenu, in the event that this information must be verified. Currently it is only possible to retrieve the names and item texts of any menu item belonging to a SapContextMenu programmatically. 

When exploring how a SapContextMenu is constructed from a control perspective, it is found that each menu item in a SapContextMenu control, is actually another SapContextMenu control. Therefore with this information it is possible to script some logic that will:

  1. Find a SapContextMenu that contains 1 or more child controls
  2. Iterate through those child controls and print the name and text information for those controls


For example, to retrieve the names and item texts that belong to a SapContextMenu accessed via a tree node from a SapTree, the following Silk4J helper method can be used:


public
void
discoverMenuNamesAndText(Desktop desktop, SapTree tree, String sNodeKey){

     tree.nodeContextMenu(sNodeKey);
     List<SapContextMenu> wins = desktop.findAll("//SapContextMenu");
     for(SapContextMenu win:wins){
          if(win.getChildren().size()>0){
               System.out.println("Parent Context Menu");

               List<TestObject> items = win.getChildren();
               for(TestObject item:items){
                    if(!((SapContextMenu)item).getName().equals("")){
                         System.out.println(" Name: "+((SapContextMenu)item).getName());
                         System.out.println(" Item Text: "+((SapContextMenu)item).getText()+"\n");
                    }
               }
          }
     }
}

 

The above method can then be used as follows:

SapTree tree desktop.<SapTree>find("//SapTree");
discoverMenuNamesAndText(desktoptree"F00005");


When executed, output similar to the following can be found in the console:

Parent Context Menu
          Name: XXEXEN
          Item Text: Execute in new window

          Name: XXECK1
          Item Text: Display documentation

          Name: XXAEND
          Item Text: Change favorite

          Name: XXECK2
          Item Text: Saved lists

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-05-25 10:04
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.