C# C“SAP自动化使用”;SAPFEWSELib";。如何从下拉列表中按下按钮?

C# C“SAP自动化使用”;SAPFEWSELib";。如何从下拉列表中按下按钮?,c#,sap,C#,Sap,我使用SAPFEWSELib自动化SAP。我在按下下拉菜单中的按钮“我猜:)”时遇到问题 此代码由SAP脚本记录自动生成。我需要用C#复制这个: 解决了 var ctrl = SapSession.ActiveWindow.FindById("wnd[0]/shellcont/shell/shellcont/shell", false); var shellToolbarContextButton = ((GuiShell)ctrl); var btnToolbarContextButton =

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

此代码由SAP脚本记录自动生成。我需要用C#复制这个:

解决了

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");

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

首先,查看第一个答案中的代码,作为对我在此处的响应所使用的静态类的引用:

其次,请尝试以下代码行:

//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"); 
这是一个很好的参考:

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