I'm using C# in order to automate SAP GUI 7.40 with sapfewse.ocx (inspired By How do I automate SAP GUI with c#)
I'stuck with an error on runtime when the script have to double click on leef of a tree.
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 ERROR: "The SAP application had to terminate due to an ABAP runtime error."
Note :
The same automation script manage with sapRotWrapper (SapROTWr.CSapROTWrapper) works
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");
Is there somebody can help me ?
Note : I've the same graphical troubles on screen during the execution, all components are not well displayed, There's a link ? (like in the question How to Automate SAP GUI 750 with C#)
Since my previous post, after a long time of experimenting unprobably solutions, I've find the way to solve this problem.
It will be resume of a mix of the different set of code i've mentionned.
The objects used to manage the connection and session must be written with 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);
But The access to tree must done with the GuiTree object
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");