cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle dynamic object IDs using TestComplete in DOM model

Occasional Contributor

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 7
Community Leader

Re: How to handle dynamic object IDs using TestComplete in DOM model

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

Occasional Contributor

Re: How to handle dynamic object IDs using TestComplete in DOM model

(ext-gen1454) Here that bolded characters are "ext-gen" only constant value. The numeric value changes every time.

Community Leader

Re: How to handle dynamic object IDs using TestComplete in DOM model

Try to find this element with this method:

 

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

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/find-m...

Highlighted
Occasional Contributor

Re: How to handle dynamic object IDs using TestComplete in DOM model

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

Regards,
Sathish Kumar K
Community Manager

Re: How to handle dynamic object IDs using TestComplete in DOM model

Thanks for your suggestions, K_Sathish_Kumar, Wamboo!

 

@Arunachalam, do they help you resolve the issue?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Community Leader

Re: How to handle dynamic object IDs using TestComplete in DOM model

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!

Occasional Contributor

Re: How to handle dynamic object IDs using TestComplete in DOM model

@K_Sathish_Kumar 

Which is not working, I can't find that Filed using that code.

Any other option is there?

New Here?
Join us and watch the welcome video:
Top Kudoed Authors