Forum Discussion

Arunachalam's avatar
Arunachalam
Occasional Contributor
5 years ago

How to handle dynamic object IDs using TestComplete in DOM model

Hi,

 

I have a problem with handling the dynamic IDs, which are changed for every refresh.

I need clarification for identifying the fields using Dynamic IDs in the DOM model.

 

Example of Dynamic ID:  ext-gen1454 

7 Replies

  • Mr_Bro's avatar
    Mr_Bro
    Champion Level 0

    Hi Arunachalam ,

     

    cau you please try using the below code and let me know if its solving your problem or not.

    Sys.Browser("chrome").Page("*")FindChild("idStr", "ext-gen*", 10);
    OR
    Aliases.FindChild("idStr", "ext-gen*", 10);
    

     

    Kind Regards,

    Sathish Kumar K

      • Wamboo's avatar
        Wamboo
        Community Hero

        Following the requests related to the example of the code found in the dynamic elements on the page, he wants to share the example functions:

         

        1) If you are expecting one of several elements on a page, e.g.
        On the form you can see one of many (known fields, e.g. text fields) use this function:

         

         

        /*
        "paremeters": "[alias(COMObject, propNames[[]], propValues[[]], depth(number), refresh(bool)]",
        "example": "searchForDynamicAnchor(Alias.mainForm, [["ClassName", "Parent.ObjectIdentifier"], ["TcxGridSite", "grdUstawionePar"]], [[ClassName", "Parent.ObjectIdentifier"], ["TcxGridSite2", "grdUstawionePar2"]], 8)",
        "result": "COMObject",
        */
        
        function searchForDynamicAnchor(alias, propNames, propValues, depth, refresh = true) {
          for (var i = 0; i < propNames.length; i++) { 
            var anchor = alias.Find(propNames[i], propValues[i], depth, refresh);
            if (anchor.Visible === false) {
              continue;
            } else {
              return anchor;
              break;
            }
          }
        }

         

        second code example in JS:

         

        var variableName = () => Unit.searchForDynamicAnchor(Alias, [["ObjectIdentifier"], ["ObjectIdentifier"]], [["edtChar"], ["edtNumber"]], 3);

         

        2) If you see a field on your website that has a field (e.g. a piece of "id" constant), then extract the code from my previous post, that is:

         

        var variableName = Aliases.Find("YourID", "regexp:(ext-gen)", 'depthValue');

         

        I hope this will help solve the problem.

         

        Good luck!

  • Wamboo's avatar
    Wamboo
    Community Hero

    Is any part of this ID constant? e.g. 'ext-' ?