Accessing Low-Level Properties

The functions SapGuiInvokeMethod, SapGuiSetProperty, and SapGuiGetProperty can be used to access the low-level properties of any control on the active screen. This makes it possible to, for example, confirm that a text control is read-only, or to determine the background color of a label.

The SAPGUI scripting API that is used for SAPGUI testing is a large COM library that allows Silk Performer to access controls and perform actions. This same COM library can be used with the above mentioned API calls. To access the list of methods and properties that individual controls offer, you must inspect the type library of the SAPGUI scripting API. For this you need a tool that facilitates the inspection of type libraries (for example the Ole32View tool that comes with Microsoft Visual Studio). With the tool, open the sapfewse.ocx file, which can be found in the SAPGUI installation directory under \FrontEnd\SapGui. The image below shows the properties that can be accessed on a label control:

Image of properties that can be accessed using the label control

To get the name of a control for which you know the control's ID, use the following call:

SapGuiGetProperty("/usr/lbl[1,2]", "Name", sOutValue);
Print("The control has the following name:" + sOutValue);

Most properties return a simple data type such as a string, number, or boolean parameter. Some properties return other objects, for example the Parent property returns the parent control of the current control. When a property returns another control, the control is temporarily cached and can be accessed via the constant SAPGUI_ACTIVEOBJECT. Here is a code example for retrieving the name of a parent property:

SapGuiGetProperty("/usr/lbl[1,2]", "Parent");
SapGuiGetProperty(SAPGUI_ACTIVEOBJECT, "Name", sOutValue);
Print("The parent control has the following name:" + sOutValue);

Differences Between 620 and 640 Clients

SAP introduced new properties and methods with its SAPGUI 640 client. With 640 you can, for example, get the background color of a label or checkbox. So, when you develop a script on 640 you must ensure that your agents also run on 640 and that the same patch level is used. Otherwise you may request properties that are not available on the agent and generate an error.

Property Overview

SAP is comprised of components that have the following properties (ComClass GuiComponent):

  • 'Name' - Name of the control
  • 'Type' - The control type in text format (for example GuiButton, GuiTextField)
  • 'TypeAsNumber' - All types have internal numbers (for example 30=GuiLabel, 31=GuiTextField)
  • 'ContainerType' - A Boolean property that defines whether or not a control is a container. Containers contain other controls as children (for example a toolbar is a container that contains toolbar buttons).
  • 'Id' - The unique ID of a control
  • 'Parent' - When a control is contained in a container this property returns the parent control

Visual components, such as controls, have additional properties (ComClass GuiVComponent):

  • 'Text' - The main text of a control (for example the text in a text control or the text on a button)
  • 'Left', 'Top', 'Width', 'Height', 'ScreenLeft', 'ScreenTop' - Number values offering details about screen coordinates and coordinates within a parent container
  • 'Changeable', 'Modified' - Boolean parameters that indicate the current state of a control (is the control changeable or read-only; has the control been modified, etc)

Each control type may have additional properties which can be seen in the COM type library via your type library inspection tool.