【问题标题】:C# SAP automation using "SAPFEWSELib". How do I press a button from a drop down list?使用“SAPFEWSELib”的 C# SAP 自动化。如何按下下拉列表中的按钮?
【发布时间】:2018-02-21 13:36:47
【问题描述】:

我使用 SAPFEWSELib 来自动化 SAP。我从下拉菜单中按下按钮时遇到问题“我猜:)”。

此代码由 SAP 脚本记录自动生成。我需要在 C# 中重现它:

session.findById("wnd[0]/shellcont/shell/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"

【问题讨论】:

    标签: c# sap


    【解决方案1】:

    解决了。

    var ctrl = SapSession.ActiveWindow.FindById("wnd[0]/shellcont/shell/shellcont/shell", false);
    var shellToolbarContextButton = ((GuiShell)ctrl);
    var btnToolbarContextButton = shellToolbarContextButton as GuiGridView;
    btnToolbarContextButton?.PressToolbarContextButton("&MB_EXPORT");
    

    【讨论】:

      【解决方案2】:

      实现相同结果的另一种方法:

      首先,将第一个答案中的代码作为对我在此处的响应中使用的静态类的引用:How do I automate SAP GUI with c#

      其次,试试下面这行代码:

      //Select Layout
              GuiGridView guiGridView = (GuiGridView) SAPActive.SapSession.FindById("wnd[0]/usr/cntlCCONTAINER/shellcont/shell");
              guiGridView.PressToolbarButton("&MB_VARIANT");
      

      为了让生活更轻松并促进更高效的编码,我在 SAPActive 类中创建了一些基本方法,这些方法接受字符串 UI 路径并将其转换为所需的对象。 以下是一些示例:

          /**
           * Takes in a string UI path Id and returns a GuiTextField linked to the
           * current session. Utilizes the SAPActive class.
           */
          public static GuiTextField TextFieldPath(string path)
          {
              GuiTextField rtnField = (GuiTextField)SAPActive.SapSession.FindById(path);
              return rtnField;
          }
          /**
           * Takes in a string UI path Id and returns a GuiMenu linked to the
           * current session. Utilizes the SAPActive class.
           */
          public static GuiMenu MenuPath(string path)
          {
              GuiMenu rtnField = (GuiMenu)SAPActive.SapSession.FindById(path);
              return rtnField;
          }
          /**
           * Takes in a string UI path Id and returns a GuiFrameWindow linked to the
           * current session. Utilizes the SAPActive class.
           */
          public static GuiFrameWindow FrameWindowPath(string path)
          {
              GuiFrameWindow rtnField = (GuiFrameWindow)SAPActive.SapSession.FindById(path);
              return rtnField;
          }
          /**
           * Takes in a string UI path Id and returns a GuiButton linked to the
           * current session. Utilizes the SAPActive class.
           */
          public static GuiButton ButtonPath(string path)
          {
              GuiButton rtnField = (GuiButton)SAPActive.SapSession.FindById(path);
              return rtnField;
          }
          /**
           * Takes in a string UI path Id and returns a GuiGridView linked to the
           * current session. Utilizes the SAPActive class.
           */
          public static GuiGridView GridViewPath(string path)
          {
              GuiGridView rtnField = (GuiGridView) SAPActive.SapSession.FindById(path);
              return rtnField;
          }
      

      现在,上面的代码可以改成如下:

      GuiGridView guiGridView = SAPActive.GridViewPath("wnd[0]/usr/cntlCCONTAINER/shellcont/shell");
      guiGridView.PressToolbarButton("&MB_VARIANT"); 
      

      这是一个很好的参考:https://help.sap.com/viewer/b47d018c3b9b45e897faf66a6c0885a8/760.00/en-US/4af24c3281fb4d6a809e53238562d3b2.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-22
        • 2022-11-24
        • 1970-01-01
        • 2021-11-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多