问题描述
我正在使用C#以便通过sapfewse.ocx自动执行SAP GUI 7.40 (受How do I automate SAP GUI with c#启发)
当脚本必须双击树的叶子时,我在运行时出错。
private GuiApplication sapEngine { get; set; }
private GuiConnection sapConnexion { get; set; }
private GuiSession sapSession { get; set; }
sapEngine = new GuiApplication();
sapConnexion = sapEngine.OpenConnection(sapGUIConfig.EndPoint,Sync:true);
sapSession = (GuiSession)sapConnexion.Sessions.Item(0);
// ...
GuiTree treeFilters = getTreePath("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell");
treeFilters.ExpandNode(" 1");
treeFilters.SelectNode(" 16");
treeFilters.TopNode = " 15";
treeFilters.DoubleClickNode(" 16");
// Crash Here after DoubleClickNode Method
SAP错误:“由于ABAP运行时错误,SAP应用程序不得不终止。”
注意:
使用sapRotWrapper(SapROTWr.CSapROTWrapper)管理的同一自动化脚本
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);
// ...
sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").expandNode(" 1");
sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").selectNode(" 16");
sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").topNode = " 15";
sapSession.FindById("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").doubleClickNode(" 16");
有人可以帮助我吗?
注意:在执行过程中,我在屏幕上遇到了相同的图形问题,所有组件均未正确显示,有链接吗? (例如问题How to Automate SAP GUI 750 with C#中的内容)
解决方法
自从我上一篇文章以来,经过长时间尝试不可能的解决方案,我已经找到了解决此问题的方法。
它将是我提到的不同代码集的混合体。
用于管理连接和会话的对象必须使用sapRotWrapper(
using SAPFEWSELib;
//...
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);
但是对树的访问必须通过GuiTree对象完成
GuiTree treeFilters = getTreePath("wnd[0]/usr/ssub%_SUBSCREEN_%_SUB%_CONTAINER:SAPLSSEL:2001/ssubSUBSCREEN_CONTAINER2:SAPLSSEL:2000/cntlSUB_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell");
treeFilters.ExpandNode(" 1");
treeFilters.SelectNode(" 16");
treeFilters.TopNode = " 15";
treeFilters.DoubleClickNode(" 16");