Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

Great New Method GetObjectTree in Current SAP GUI Scripting API

The patch level 3 of SAP GUI for Windows 7.70 has been available since six days. With this new version offers the SAP GUI Scripting API a great new method called GetObjectTree. The method is domiciled in the GuiSession object. It delivers all requested attributes of the elements of the given ID as JSON (JavaScript Object Notation) object.

A simple call of …

JSONTree = session.GetObjectTree("wnd[0]")

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.CreateTextFile("Test.json",True)
oFile.Write JSONTree
oFile.Close

… delivers all IDs of the elements from window 0 of the session.

But it is also possible to add the properties of the elements you are interested in, here an example:

arrayOfProps = Array("Id", "Text", "Type", "Name", _
  "ScreenLeft", "ScreenTop", "Left", "Top", "Height", "Width", _
  "Handle", "ToolTip", "DefaultToolTip", "IconName", _
  "Changeable", "ContainerType")
JSONTree = session.GetObjectTree("wnd[0]", arrayOfProps)

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.CreateTextFile("Test.json", True)
oFile.Write JSONTree
oFile.Close

This delivers much more information.

Great new method. This allows us to get a complete overview of all UI elements at runtime of a script in a very simple way.

However, things only get really interesting with scripting languages that also support JSON objects, e.g. like PowerShell.

$arrayOfProps = @("Id", "Text", "Type", "IconName", "Tooltip");

$JSONTree = Invoke-Method -object $session -methodName "GetObjectTree" -methodParameter @("wnd[0]", $arrayOfProps);
$AllElements = ConvertFrom-Json $JSONTree;

$Elements = $AllElements.children.children
ForEach($Element in $Elements) {
  $Element.properties.Id;
}

A very interesting feature that can greatly simplify some approaches.

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.