Automatisation C # SAP GUI: DoubleClickNode génère une erreur d'exécution

Sep 08 2020

J'utilise C # afin d'automatiser SAP GUI 7.40 avec sapfewse.ocx (inspiré de Comment automatiser SAP GUI avec c # )

Je suis coincé avec une erreur lors de l'exécution lorsque le script doit double-cliquer sur le leef d'un arbre.

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
    

ERREUR SAP: "L'application SAP a dû s'arrêter en raison d'une erreur d'exécution ABAP."

Noter :

Le même script d'automatisation géré avec sapRotWrapper (SapROTWr.CSapROTWrapper) fonctionne

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

Y a-t-il quelqu'un qui peut m'aider?

Remarque: j'ai les mêmes problèmes graphiques à l'écran lors de l'exécution, tous les composants ne sont pas bien affichés, y a-t-il un lien? (comme dans la question Comment automatiser SAP GUI 750 avec C # )

Réponses

Nicolas Sep 09 2020 at 14:48

Depuis mon précédent article, après une longue période d'expérimentation de solutions improbables, j'ai trouvé le moyen de résoudre ce problème.

Ce sera le résumé d'un mélange des différents ensembles de codes que j'ai mentionnés.

Les objets utilisés pour gérer la connexion et la session doivent être écrits avec 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);

Mais l'accès à l'arbre doit se faire avec l'objet 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");