Forum Discussion

engise's avatar
engise
Occasional Contributor
13 years ago

Problem with dynamic objects

Hello all,

I am new to this so I will try to explain this as best as I can. I am
writing an automated script on Testcomplete 7 for a web application
written on Java at my company, actually I am just fixing some minor
bugs. One of the most irritating things are dynamic objects (not sure if
you call them that). Once I restart Internet Explorer the ids of the
objects changes and I get an error in the log like this "Unable to find
the object SwingObject("UILazyComponent$BasicLazyComponent", "", 5)".
That 5 changes every time. And when it changes I have to go in to the
source code to change it from 1 to 5 or something along the lines of
that. Is there a way to make the script find the id by itself, because
the script has to be automated and the people using it wont have any
knowledge of Tescomplete or Java or JavaScript.



Thank you for your time !

Best regards,

- engise

4 Replies

  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)
    Hello,



    The first thing to do is to find which of the object properties (apart
    from the "changeable" ID) allow the unique identification of the target
    control. Often, it's not a single property, but a set of several
    properties. You may explore object members in the
    [url=http://smartbear.com/support/viewarticle/11024/]Object
    Browser[/url] or 
    Object Spy
    to determine such properties.

    Once they are determined, you may either use them as recognition
    attributes for
    [url=http://smartbear.com/support/viewarticle/11327/]Name
    Mapping[/url] (see
    [url=http://smartbear.com/support/viewarticle/12447/]Mapping
    Application Objects[/url]), or pass them as object search criteria (as
    described in
    [url=http://smartbear.com/support/viewarticle/12729/]Finding Objects
    on Web Pages[/url]).






  • engise's avatar
    engise
    Occasional Contributor
    Hello,

    thanks for your help but I cant seem to fix this issue with NameMapping ... Is there another alternative for this ? Maybe a check that looks at the ("UILazyComponent$BasicLazyComponent", "", 5) and check if the id is 1,2,3,4,5 ... etc and if it finds the exact id to use that ?
  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)
    Hello,



    As an alternative to NameMapping, you may use scripting search methods: Find, FindChild, FindAll, FindAllChildren, Page.NativeWebObject.Find, and others.



    >>Maybe a check that looks at the ("UILazyComponent$BasicLazyComponent", "", 5) and check if the id is 1, 2, 3, 4, 5 ... etc and if it finds the exact id to use that?

    The index of 5 means that there are at least 6 similar objects (descendants of the UILazyComponent$BasicLazyComponent class; having no caption or accessible name). Thus, the main difficulty is to determine which of these objects is the one you need to test. I assume that some of the object members will allow determining the needed object. For instance, the target control is visible on screen (VisibleOnScreen=True), while the others are hidden (VisibleOnScreen=False). Without examining your application, I can't say exactly which of the fields or properties this would be.  



    Having spotted the distinctive criteria, you can perform a search for the object:



      function Test()

    {

      var PropArray, ValuesArray, theControl;

     

      // Creates arrays of property names and values

      PropArray = new Array("JavaClassName", "AWTComponentName", "VisibleOnScreen");

      ValuesArray = new Array("UILazyComponent$BasicLazyComponent", "", true);



      // Searches for the control

      theControl = Sys.Process("TheTestedAppName").Find(PropArray, ValuesArray, 5);



      // Processes the search results

      if (theControl .Exists)

        Log.Message(theControl .FullName);

      else

        Log.Error("The object was not found.");

    }