How to set current cell on SAP GUIContainerShell in C#?

喜欢而已 提交于 2019-12-10 11:59:31

问题


I am automating my work with SAP GUI script at the moment and whilst trying to recreate the recorded macro I am having an issue at one particular point which I don't know how to translate.

session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").setCurrentCell 1,"MAKTX2"
session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").doubleClickCurrentCell
session.findById("wnd[1]/tbar[0]/btn[0]").press

I have read through the SAP GUI Scripting API pdf and am struggling to see how I action the .setCurrentCell 1,"MAKTX2" part. I am accessing the container cell with the following:

GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

How do I make "materials" double click "MAKTX2"?

Edit: Full sap script:

SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper();
                    object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
                    object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);
                    GuiApplication GuiApp = (GuiApplication)engine;
                    GuiConnection connection = (GuiConnection)GuiApp.Connections.ElementAt(0);
                    GuiSession session = (GuiSession)connection.Children.ElementAt(0);
                    GuiFrameWindow frame = (GuiFrameWindow)session.FindById("wnd[0]");
                    GuiTextField jobsite = (GuiTextField)session.FindById("wnd[0]/usr/subSA_0100_1:SAPMZCX_CSDSLSBM5001_OFS_OTS:2410/subSA_2410_1:SAPMZCX_CSDSLSBM5001_OFS_OTS:2510/ctxtKUWEV-KUNNR");
                    jobsite.Text = "I033";
                    frame.SendVKey(0);
                    GuiLabel aggregates = (GuiLabel)session.FindById("wnd[1]/usr/lbl[12,3]");
                    aggregates.SetFocus();
                    GuiFrameWindow frame2 = (GuiFrameWindow)session.FindById("wnd[1]");
                    frame2.SendVKey(1);
                    GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

回答1:


To be honest I can't help you with C#, but perhaps the SAP interface is generic enough anyway. Thing is, session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell") gives you a reference to an object of type GuiShell or GuiContainerShell or whatever it's called. On this reference, you can call the methods defined for this type. So in the same way, when you do

session.findById("wnd[0]/shellcont/shell/shellcont[1]/shell").setCurrentCell 1,"MAKTX2"

You're just getting the reference first, and then applying the method setCurrentCell on it, all on the same line.

When you did in C#

GuiContainerShell materials = (GuiContainerShell)session.FindById("wnd[0]/shellcont/shell/shellcont[1]/shell");

you gave this reference a name materials, and provided that line works correctly, I guess you can just say now:

materials.setCurrentCell(1, "MAKTX2")
materials.doubleClickCurrentCell


来源:https://stackoverflow.com/questions/50130754/how-to-set-current-cell-on-sap-guicontainershell-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!