title: Recursively get all children of SAP Gui Session in c#
body: <p>I am looking to loop through all SAP GuiComponents in c# but am struggling to get all the children of children of a gui session.</p>
  
  <p>This is what I have so far (initially passing session.ActiveWindow.Children to nodes):</p>
  
  <pre><code> private void IterateFindIDByNAme(GuiComponentCollection nodes, string searchstring)
      {
          if (foundID == "")
          {
              foreach (GuiComponent node in (GuiComponentCollection)nodes)
              {
                  var comp = node;
                  if (comp.Name.Contains(searchstring))
                      foundID = comp.Id;
                  else
                  {
                      try
                      {
                          FindIDByNAme((GuiComponentCollection)node, searchstring);
                      }
                      catch { }
                  }
              }
          }
      }
  </code></pre>
  
  <p>Its able to get all the child elements of session.ActiveWindow but when trying to cast all the children to GuiComponentCollections its falling over.</p>
  
  <p>This would be irrelevant if I could use the FindByName function but for some reason it is not working on the SAP screen i am currently working on (it does work on others, not sure why).</p>
  
  <p>The ID of the field is:</p>
  
  <pre><code>wnd[0]/usr/subBCA_SUB_HEADER:SAPLBANK_BDT_CTRL:0100/subSUBS_DETAIL:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:4038/subA01P02:SAPLBCA_DYN_CN_CNMANO:0002/ctxtBCA_DYN_CONTRACT_ORGENTRY-ORGUNIT
  </code></pre>
  
  <p>and the function I am trying is:</p>
  
  <pre><code>((GuiTextField)session.FindByName("BCA_DYN_CONTRACT_ORGENTRY-ORGUNIT", "GuiTextField")).Text = "Test";
  </code></pre>
  
  <p>The findbyid works fine, but not findbyname?</p>
  
  <p>I know this is 2 questions, but kind of related.</p>