Forum Discussion

KSQian's avatar
KSQian
Contributor
7 years ago

FindAllChildren doesn't really return an array

For JavaScript, the docs claim it returns an array. But it really doesn't. It returns an array like object iterable. 

 

Please ask devs to return an actual javascript array so I don't need to convert them :) or at least mixin the Array functions like map, filter etc. 

 

let SomeObjects = Grid.FindAllChildren(["ClrClassName"],["ComboBox"],10)

Log.Message(Array.isArray(SomeObjects )) // false 
Log.Message(Array.isArray(Array.from(SomeObjects ))) // true

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Correct... it's not a JavaScript array but it is an object that acts like an array and you can use it as an array.  Below is the sample code provided for the method for JavaScript... note it still has options for "length" and the square bracket notation for array elements.  For most needs for finding a set of onscreen objects that match a particular set of properties, this is usually sufficient.

    Feature requests, BTW, have a different place here on the community, though... 

     

    function FindEditbuttons()
    {
      var p, w, textBoxes, i;
    
      // Obtain the Notepad process
      p = Sys.Process("notepad");
    
      // Open the Font dialog
      p.Window("Notepad", "*").MainMenu.Click("Format|Font...");
      w = p.Window("#32770", "Font");
    
      // Search for all edit buttons in the Font dialog
      textBoxes = w.FindAllChildren("WndClass", "Edit", 5).toArray();
    
      // Log the search results
      if (textBoxes.length > 0)
      {
        for (i = 0; i < textBoxes.length; i++)
          Log.Message("FullName: " + textBoxes[i].FullName + "\r\n" +
                      "Text: " + textBoxes[i].wText);
        Log.Message("Total number of found edit buttons: " + textBoxes.length);
      }
      else
        Log.Warning("No edit buttons found.");
    }

     

    • KSQian's avatar
      KSQian
      Contributor

      Thanks!

       

      Yea I wanted to nitpick because I wanted to organically perform functional programming on it. 

       

      I think if they update their docs that'd be okay :) 

       

      let list = Array.from(Grid.FindAllChildren(...)) // Use Array.from to convert their obj into an actual array.
      
      return list.map(obj=>obj.wText).filter(text=>text!='Error') // convert to array of just obj.wText, then filter it to discard the ones that are not 'Error'. 
      
      

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Documentation says that it's a "safe array"... a microsoft array data type.  Probably has something to do with the code language TestComplete is written in...  JavaScript is supported in TC as a scripting language, however, behind the scenes, these objects and functions and methods are running in some other language and, therefore, returns things that are not native to the scripting language of choice.