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:
- Find a SapContextMenu that contains 1 or more child controls
- 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:
publicvoid 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(desktop, tree, "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