I am currently automating a SAP GUI tool to get the response time of a tcode via STAD. I tried in first in VBA Excel and it works fine. But upon migrating to Visual Studio 2013, it encounters below unhandled exception:
Line of code:
If statusbar_msg = "" Then
jmsession.FindById("wnd[0]/tbar[0]/okcd").Text = "/nstad"
jmsession.FindById("wnd[0]").sendVKey(0)
jmsession.FindById("wnd[0]/usr/txtSELECTION-SREADTI").Text = "00:20:00"
jmsession.FindById("wnd[0]/usr/txtSELECTION-SBENU").Text = Form1.TextBox1.Text
jmsession.FindById("wnd[0]/usr/txtSELECTION-STCOD").Text = tcode(i, 1)
jmsession.FindById("wnd[0]/usr/txtSELECTION-STCOD").SetFocus()
jmsession.FindById("wnd[0]").sendVKey(0)
res_Time_ms = jmsession.FindById("wnd[0]/usr/lbl[113,9]").Text
jmsession.FindById("wnd[0]/usr/lbl[113,9]").Text ---> in this line an exception is thrown.
The rest of the code works except for this line.
Below is the exception:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: The control could not be found by id.
When executed using CTRL+F5
************** Exception Text ************** System.Runtime.InteropServices.COMException (0x0000026B): The control could not be found by id. at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at SAPFEWSELib.ISapSessionTarget.FindById(String Id, Object Raise)
User contributions licensed under CC BY-SA 3.0