<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: GUI scripting. How not traverse object tree each time? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061631#M4507249</link>
    <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;stefan.schnell&lt;/SPAN&gt; Hi Stefan. It seems that you only the person can help me there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Dec 2019 14:12:08 GMT</pubDate>
    <dc:creator>former_member237609</dc:creator>
    <dc:date>2019-12-02T14:12:08Z</dc:date>
    <item>
      <title>GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaq-p/12061627</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I have several questions&lt;/P&gt;
  &lt;P&gt;1. Is it possible to not traverse object tree each time i want to access specific field?&lt;/P&gt;
  &lt;P&gt;So far i use Object.children.item() and so on. But it seems that anyway SAP traverse all the elements. &lt;/P&gt;
  &lt;P&gt;I thought it would be more performant but after profiling it seems not.&lt;/P&gt;
  &lt;P&gt;How to avoid that? Keep some kind of cache to access elements directly &lt;/P&gt;
  &lt;P&gt;2. Some GUI events doesn’t work: Hit, Error.&lt;/P&gt;
  &lt;P&gt;I catch them from Session object (Session_Hit, etc).&lt;/P&gt;
  &lt;P&gt;CreateSession and DestroySession works just fine.&lt;/P&gt;
  &lt;P&gt;The idea is same as built-in recorder: listen to user events and record script but with different payload (trying to avoid continuous session.FindById... and make element names human-readable).&lt;/P&gt;
  &lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2019 08:57:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaq-p/12061627</guid>
      <dc:creator>former_member237609</dc:creator>
      <dc:date>2019-11-19T08:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061628#M4507246</link>
      <description>&lt;P&gt; @stefan.schnell Hi Stefan. It seems that you only the person can help me there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 10:43:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061628#M4507246</guid>
      <dc:creator>former_member237609</dc:creator>
      <dc:date>2019-12-02T10:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061629#M4507247</link>
      <description>&lt;P&gt;If you do a comment under a question/answer and you want to target someone else than the question/answer' author, the only solution is to copy/paste their hyperlinked name so that the person receives a warning (NB: @ doesn't work)&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 13:41:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061629#M4507247</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-12-02T13:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061630#M4507248</link>
      <description>&lt;P&gt;In SAP GUI for Windows, there is the Recorder in the System menu, which records your input and generate a VBScript.&lt;/P&gt;&lt;P&gt;It generates this kind of lines:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;set field = FindById( "/app/con[0]/ses[0]/wnd[0]/usr/lblRS38M-PROGRAMM" )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Dec 2019 13:48:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061630#M4507248</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-12-02T13:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061631#M4507249</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;stefan.schnell&lt;/SPAN&gt; Hi Stefan. It seems that you only the person can help me there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 14:12:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061631#M4507249</guid>
      <dc:creator>former_member237609</dc:creator>
      <dc:date>2019-12-02T14:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061632#M4507250</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;I do understand it. But question is as in subject how to not traverse object model as it happens with finbyid function. &lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 14:13:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061632#M4507250</guid>
      <dc:creator>former_member237609</dc:creator>
      <dc:date>2019-12-02T14:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061633#M4507251</link>
      <description>&lt;P&gt;Hello Conrad,&lt;/P&gt;&lt;P&gt;very interesting questions and a very interesting perspective.&lt;/P&gt;&lt;P&gt;1. I have never done a profiling of this kind. Here my example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TStart = Timer()
For i = 1 To 100
  session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = CStr(i)
Next
TEnd = Timer()
MsgBox CStr(TEnd - TStart) 'Result 0,8

Set Field = session.findById("wnd[0]/usr/txtRSYST-MANDT")
TStart = Timer()
For i = 1 To 100
  Field.Text = CStr(i)
Next
TEnd = Timer()
MsgBox CStr(TEnd - TStart) 'Result 0,4
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It's about twice as fast to work with objects instead of the findById with the ID.&lt;/P&gt;&lt;P&gt;Wow...&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; and you give the answer, cache the UI element in an object. I don't know another way.&lt;/P&gt;&lt;P&gt;2. The hit event works with the following example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Sub ses_Error(Sess, ErrID, Desc1, Desc2, Desc3, Desc4)
  MsgBox(Desc1 &amp;amp; vbCrLf &amp;amp; Desc2 &amp;amp; vbCrLf &amp;amp; Desc3 &amp;amp; vbCrLf &amp;amp; Desc4)
End Sub

Sub ses_Hit(Sess, Comp, IObj)
  MsgBox(IObj) 'Works perfect
End Sub

Set SapGuiAuto  = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children(0)
Set session    = connection.Children(0)

If IsObject(WScript) Then
  WScript.ConnectObject session, "ses_"
End If

'-To use hit event it is necessary to set this property-----------------
session.findById("wnd[0]").ElementVisualizationMode = True

MsgBox "Press to end"
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can't simulate the error event, but I assume this code example works.&lt;/P&gt;&lt;P&gt;How do you simulate an access denial to a a SAP GUI ActiveX control in a running script?&lt;/P&gt;&lt;P&gt;Let us know your experience.&lt;/P&gt;&lt;P&gt;Best regards&lt;BR /&gt;Stefan&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 08:17:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061633#M4507251</guid>
      <dc:creator>Stefan-Schnell</dc:creator>
      <dc:date>2019-12-05T08:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: GUI scripting. How not traverse object tree each time?</title>
      <link>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061634#M4507252</link>
      <description>&lt;P&gt;Hi everybody. Sorry for such a late reply.&lt;/P&gt;&lt;P&gt;It seems that there's misunderstanding. &lt;/P&gt;&lt;P&gt;Set ScreenA = Session.FindById("BLA")&lt;/P&gt;&lt;P&gt;Set ScreenB = Session.FindById("BLABLA")&lt;/P&gt;&lt;P&gt;ScreenB.DoubleClick 'entered 2nd screen.&lt;/P&gt;&lt;P&gt;ScreenB.MoveBack 'entered 1st screen. &lt;/P&gt;&lt;P&gt;ScreenA.Text 'object is not available anymore because SAP cleaned reference.&lt;/P&gt;&lt;P&gt;Set ScreenA = Session.FindById("BLA") 'so you've to find it again which is obviously costy. I often faced with such an operation in loop where you have to switch between 2 screens.&lt;/P&gt;&lt;P&gt;So the original question is that how can i keep reference to ScreenA between screen change?&lt;/P&gt;&lt;P&gt;I think it's limitation of host application (SAP) so its should be changed from there. But maybe there's some workaround exist which i'm unaware of.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 13:52:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/gui-scripting-how-not-traverse-object-tree-each-time/qaa-p/12061634#M4507252</guid>
      <dc:creator>former_member237609</dc:creator>
      <dc:date>2020-01-15T13:52:43Z</dc:date>
    </item>
  </channel>
</rss>

