C# 如何使用C实现SAP GUI 750的自动化#
问题:如何打开新的SAP GUI应用程序,以SAP登录而不是SAP轻松访问为目标 我知道这似乎是一个重复的问题,但它更多的是一个补充问题。由于我缺乏声誉积分,我无法在评论部分提问,因此请原谅我 我能够使用C成功地实现到SAP的连接,但是,它连接到的是“SAP轻松访问”,而不是“SAP登录”——一个更具视觉吸引力的GUI。我不一定关心视觉外观;问题在于某些按钮或文本输入字段不可用或不可见。 这是一张照片: 我认为问题在于DLL库或我不知道如何启动SAP登录实例并将其附加到会话 以下是我的代码,不包括敏感数据:C# 如何使用C实现SAP GUI 750的自动化#,c#,sap-gui,C#,Sap Gui,问题:如何打开新的SAP GUI应用程序,以SAP登录而不是SAP轻松访问为目标 我知道这似乎是一个重复的问题,但它更多的是一个补充问题。由于我缺乏声誉积分,我无法在评论部分提问,因此请原谅我 我能够使用C成功地实现到SAP的连接,但是,它连接到的是“SAP轻松访问”,而不是“SAP登录”——一个更具视觉吸引力的GUI。我不一定关心视觉外观;问题在于某些按钮或文本输入字段不可用或不可见。 这是一张照片: 我认为问题在于DLL库或我不知道如何启动SAP登录实例并将其附加到会话 以下是我的代码,不
using System;
using SAPFEWSELib;
namespace RS_PostSettlementDataPull
{
//SAPActive class to perform script operations
public class SAPActive
{
//Class Member accessors
public static GuiApplication SapGuiApp { get; set; }
public static GuiConnection SapConnection { get; set; }
public static GuiSession SapSession { get; set; }
/**
* Takes in a connection string and creates a GuiApplication linking
* the SAP Connection and Session.
*
* Accepts DEFAULT connection.
*/
public static void OpenSap(string env)
{
SAPActive.SapGuiApp = new GuiApplication(); //Need a way to explicitly create SAP Logon app
string connectString = null;
if (env.ToUpper().Equals("DEFAULT"))
{
connectString = "1.0 Test ERP (DEFAULT)";
}
else
{
connectString = env;
}
SAPActive.SapConnection = SAPActive.SapGuiApp.OpenConnection(connectString, Sync: true); //creates connection
SAPActive.SapSession = (GuiSession)SAPActive.SapConnection.Sessions.Item(0); //creates the Gui session off the connection you made
}
/**
* Takes in connection parameters to login to the SAP session.
*/
public static void login(string myclient, string mylogin, string mypass, string mylang)
{
GuiTextField client = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField");
GuiTextField login = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField");
GuiTextField pass = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField");
GuiTextField language = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField");
client.SetFocus();
client.Text = myclient;
login.SetFocus();
login.Text = mylogin;
pass.SetFocus();
pass.Text = mypass;
language.SetFocus();
language.Text = mylang;
//Press the green checkmark button which is about the same as the enter key
GuiButton btn = (GuiButton)SapSession.FindById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/btn[0]");
btn.SetFocus();
btn.Press();
}
/**
* 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;
}
/**
* Main class that acts as the driving SAP GUI Script engine.
*/
public static void Main(string[] args)
{
SAPActive.OpenSap("SENSITIVE");
SAPActive.login("100", "SENSITIVE", "SENSITIVE", "EN");
SAPActive.SapSession.StartTransaction("IW59");
GuiMenu guiMenu;
GuiFrameWindow guiFrameWindow;
GuiTextField guiTextField;
GuiButton guiButton;
guiMenu = SAPActive.MenuPath("wnd[0]/mbar/menu[2]/menu[0]/menu[0]");
guiMenu.Select();
guiTextField = SAPActive.TextFieldPath("wnd[1]/usr/txtV-LOW");
guiTextField.SetFocus();
guiTextField.Text = "SENSITIVE";
guiTextField = SAPActive.TextFieldPath("wnd[1]/usr/txtENAME-LOW");
guiTextField.Text = "";
guiFrameWindow = SAPActive.FrameWindowPath("wnd[1]");
guiFrameWindow.SendVKey(8);
guiFrameWindow = SAPActive.FrameWindowPath("wnd[0]");
guiFrameWindow.SendVKey(8);
//guiButton = SAPActive.ButtonPath("wnd[1]/tbar[0]/btn[8]");
//guiButton.SetFocus();
//guiButton.Press();
}
}
}
感谢您提供的任何帮助 我也有同样的问题。我不知道SAP是否像你写的那样连接到“SAP轻松访问” 我通过改变对象的类别来解决它:
sapEngine = new GuiApplication();
sapConnexion = sapEngine.OpenConnection(sapGUIConfig.EndPoint,Sync:true);
sapSession = (GuiSession)sapConnexion.Sessions.Item(0);
作者:
但是它可以像我在中发现的那样对您的scipt产生一些影响。非常感谢您的回复。最后,我将所有涉及SAP脚本的流程都转移到python上。有一个模块模仿SAP的VB脚本,使事情变得更简单、更高效。干杯
sapROTWrapper = new SapROTWr.CSapROTWrapper();
sapGUIROT = _sapROTWrapper.GetROTEntry("SAPGUI");
//Get the reference to the Scripting Engine
sapEngine = sapGUIROT.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, sapGUIROT, null);
sapConnexion = sapEngine.OpenConnection(sapGUIConfig.EndPoint);
sapSession = sapConnexion.Children(0);