Skip to Content


Hello community,

more and more loses the SAP GUI for Windows his unique position as primary UI and also more and more are desktop applications replaced with web applications. The SAP GUI for Windows offers for automation approaches the SAP GUI Scripting, a consolidated and technical reliable way. For web browser wrotes Prakash Upadhyay in his great blog about START (Simple Test Automation for Regression Tests) an UI Automation Framework to automate the testing of application. START bases on Selenium WebDrivers. So I think it could be advantageous to combine SAP GUI Scripting and Selenium.



So I advanced my Scripting Tracker to create also Java code, to offer the possibilty to combine SAP GUI Scripting on this language platform. To use SAP GUI Scripting with Java you need the Java COM Bridge (JaCoB).

For the web activities I use in my context the chrome web driver, an x86 application, because I use the Chrome browser. So it is necessary to use the x86 (i586) version of the JDK, also for the SAP GUI for Windows. To record the activities on the web browser I use Firefox with Selenium IDE. You see it is a very heterogeneous development environment. But after all, it works. Here an example code how to combine SAP GUI for Windows activities with any activities in a web browser. In the example I combine information from the TAC SE16 from the table DEMO_CR_CUSTOMRS with a web dynpro application DEMO_WD_CAR_RENTAL – this is not really useful but shows the horizons.


package de.stschnell;

  import com.jacob.activeX.*;
  import java.util.HashMap;
  import java.util.Map;
  import org.openqa.selenium.*;
  import org.openqa.selenium.remote.*;
public class SAPGUIScriptingWithSelenium {

  public static void main(String[] args) {

    ActiveXComponent SAPROTWr, GUIApp, Connection, Session, Obj;
    Dispatch ROTEntry;
    Variant Value, ScriptEngine;
    String cnt = "0";


    //-Set SapGuiAuto = GetObject("SAPGUI")-----------------------------
    SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
    try {
      ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
      //-Set application = SapGuiAuto.GetScriptingEngine----------------
      ScriptEngine =, "GetScriptingEngine");
      GUIApp = new ActiveXComponent(ScriptEngine.toDispatch());

      //-Set connection = application.Children(0)-----------------------
      Connection = new ActiveXComponent(
        GUIApp.invoke("Children", 0).toDispatch()
      //-Set session = connection.Children(0)---------------------------
      Session = new ActiveXComponent(
        Connection.invoke("Children", 0).toDispatch()

      //-Open SE16------------------------------------------------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
      Obj.setProperty("text", "/nse16");
      Obj = new ActiveXComponent(Session.invoke("findById", 
      Obj.invoke("sendVKey", 0);

      //-Open selection view for table DEMO_CR_CUSTOMRS-----------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
      Obj.setProperty("text", "DEMO_CR_CUSTOMRS");
      Obj = new ActiveXComponent(Session.invoke("findById", 

      //-Open dialog "Number of Entries"--------------------------------
      Obj = new ActiveXComponent(Session.invoke("findById", 

      //-Get the number of entries--------------------------------------
      Obj = new ActiveXComponent(Session.invoke("findById", 
      Value = Obj.getProperty("text");
      cnt = Value.toString();

    } catch (Exception e) {
    } finally {
    //-If number of entries > 0-----------------------------------------
    if (cnt != "0") {

      //-Set path to chromedriver---------------------------------------
        "C:/Program Files/Selenium/chromedriver.exe");

      //-Set path to chrome browser-------------------------------------
      Map<String, Object> chromeOptions = new HashMap<String, Object>();
      chromeOptions.put("binary", "C:/Program Files/Google/Chrome/Application/chrome.exe");
      DesiredCapabilities capabilities =;
      capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);        
      //-Opens a web browser window-------------------------------------
      WebDriver driver = new ChromeDriver(capabilities);

      //-Do your activities in the browser------------------------------






Here Scripting Tracker which  records Java code from the SAP GUI for Windows activities:

Here Firefox with Selenium IDE to record web activities:

Here the SAP GUI for Windows with SAP GUI Scripting and Eclipse in debug mode side by side:

Here Chrome with Eclipse in debug mode side by side:



A longer time ago I wrote here about the possibility to use PowerShell with SAP GUI Scripting. Selenium offers, besides Java, also dotNET libraries. On this way it is possible to combine SAP GUI Scripting with the WebDriver also on the base of PowerShell.

Here the same example in PowerShell.



  #-Set SapGuiAuto = GetObject("SAPGUI")--------------------------------
  $SapGuiAuto = Get-Object( , "SAPGUI")
  If ($SapGuiAuto -isnot [__ComObject]) {

  #-Set application = SapGuiAuto.GetScriptingEngine---------------------
  $application = Invoke-Method $SapGuiAuto "GetScriptingEngine"
  If ($application -isnot [__ComObject]) {
    Free-Object $SapGuiAuto

  #-Set connection = application.Children(0)----------------------------
  $connection = Get-Property $application "Children" @(0)
  If ($connection -eq $Null) {
    Free-Object $SapGuiAuto

  #-Set session = connection.Children(0)--------------------------------
  $session = Get-Property $connection "Children" @(0)
  If ($session -eq $Null) {
    Free-Object $SapGuiAuto

  #-Open SE16-----------------------------------------------------------
  $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/okcd")
  Set-Property $ID "text" @("/nse16")
  $ID = Invoke-Method $session "findById" @("wnd[0]")
  Invoke-Method $ID "sendVKey" @(0)

  #-Open selection view for table DEMO_CR_CUSTOMRS----------------------
  $ID = Invoke-Method $session "findById" @("wnd[0]/usr/ctxtDATABROWSE-TABLENAME")
  Set-Property $ID "text" @("DEMO_CR_CUSTOMRS")
  $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[1]/btn[7]")
  Invoke-Method $ID "press"

  #-Open dialog "Number of Entries"-------------------------------------
  $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[1]/btn[31]")
  Invoke-Method $ID "press"

  #-Get the number of entries-------------------------------------------
    $ID = Invoke-Method $session "findById" @("wnd[1]/usr/txtG_DBCOUNT")
    $Value = Get-Property $ID "text"

  #-If number of entries > 0--------------------------------------------
  If ($Value -ne 0) {
    #-Load libraries----------------------------------------------------
    [System.Reflection.Assembly]::LoadFrom("C:\Program Files\Selenium\Selenium.WebDriverBackedSelenium.dll")
    [System.Reflection.Assembly]::LoadFrom("C:\Program Files\Selenium\WebDriver.dll")
    [System.Reflection.Assembly]::LoadFrom("C:\Program Files\Selenium\WebDriver.Support.dll")

    #-Set path to chrome browser----------------------------------------
    $Options = New-Object OpenQA.Selenium.Chrome.ChromeOptions
    $Options.BinaryLocation = "C:/Program Files/Google/Chrome/Application/chrome.exe"

    #-Opens a web browser window----------------------------------------
    $WebDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver("C:\Program Files\Selenium", $Options)
    $WebDriver.Url = ""

    #-Do your activities in the browser---------------------------------





On this ways is it possible to combine SAP GUI Scripting with e.g. WebDynpro or UI5 applications. So you can reach a higher integration level in your automation approaches.

Enjoy it.



To report this post you need to login first.


You must be Logged on to comment or reply to a post.


    Thanks for this.I was able to login and search for some objects in SAP UI.Now i am stucked in reading data from a grid.After searching system generate a grid.Now i want to read the data from the grid .

    I can click on grid cells and rows but i can not read the data.How to read the data from grid.

    sample code of clicking a row and cell

    Obj = new ActiveXComponent(Session.invoke("findById", "wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").toDispatch());
    Obj.setProperty("selectedRows", "0");
    Obj = new ActiveXComponent(Session.invoke("findById", "wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").toDispatch());
    1. Stefan Schnell Post author

      Hello Mohamed,

      thanks for your reply.

      Sorry but I have no Java sample code to read an ALV grid, but you can find here and here examples in VBScript. I assume that it should looks like this:

      Table = new ActiveXComponent(Session.invoke("findById", "wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").toDispatch());
      Rows = Table.getProperty("RowCount") - 1;
      Cols = Table.getProperty("ColumnCount") - 1;
      for (int i = 0; i < Rows; i++) {
        for (int j = 0; j < Cols; j++) {
          string Value = Table.invoke("GetCellValue", i, j);

      Let us know your results.

      Best regards



        Thanks for the response.

           Rows = Table.getProperty(“RowCount”) – 1;

           Cols = Table.getProperty(“ColumnCount”) – 1;

        above returns the no of column and rows.But

            Table.invoke(“GetCellValue”, 1, 1);

        this returns an exception.I have tried with different  row and column id’s as well.

        Exception – Method threw ‘’ exception.

        Detailed message Invoke of: GetCellValue
        Source: SAP Frontend Server


        Stack trace –

        0 = {StackTraceElement@1577} “ Method)”
        1 = {StackTraceElement@1578} “”
        2 = {StackTraceElement@1579} “”
        3 = {StackTraceElement@1580} “”
        4 = {StackTraceElement@1581} “com.jacob.activeX.ActiveXComponent.invoke(”

        1. Stefan Schnell Post author

          Hello Mohamed,

          try this:

          arg = new Variant[2];
          Table = new ActiveXComponent(Session.invoke("findById", "wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").toDispatch());
          Rows = Table.getProperty("RowCount") - 1;
          Cols = Table.getProperty("ColumnCount") - 1;
          for (int i = 0; i < Rows; i++) {
            for (int j = 0; j < Cols; j++) {
              arg[0] = new Variant(i);
              arg[1] = new Variant(j);
              string Value = Table.invoke("GetCellValue", arg);

          Let us know your results.


          1. MOHAMED RIFAD


            Thanks for the reply.Appreciate it.The above code also returns the same error.But I am lucky enough to come across a code which worked for me.

            Dispatch dispatch = Session.invoke("findById", "wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").toDispatch();
            The above code returns the row 1's objectid columns value.

Leave a Reply