Forum Discussion

nfarr7's avatar
nfarr7
New Member
7 days ago

Inconsistent, dynamically named objects

I am working with an ASP webapp and am dealing with an issue where object names/identifiers change on a regular basis, causing tests to fail because the object is not being recognized like it was prior to failing. How do I deal with this? For example, an object may be called 'textnode9' today, and 'textnode17' tomorrow. The documentation is unclear to me and any help is highly appreciated!

 

I've come across these bits of documentation from Smart Bear:

Handle Dynamic Identifiers | TestComplete Documentation

Regular Expressions Syntax | TestComplete Documentation

3 Replies

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Icon for Champion Level 3 rankChampion Level 3

    For dynamic web pages like yours, it really helps to get familiar with the page’s HTML DOM and understand how element attributes change. TestComplete’s Object Spy and Object Browser are great tools, but I usually use the browser’s Developer Tools (F12) or Inspect Element to copy the full XPath before and after a page change — that makes it easy to also see which parts of the path are dynamic.

    Try to avoid using dynamic values wherever possible. When you can’t, use wildcards or regular expressions in your Name Mapping, or with the FindChild() and FindAllChildren() methods.

    One effective approach is to anchor your XPath to a stable ancestor element and use the contains() function. For example:

    /html/body/div[3]/div[2]/div[5]/span[@id='textnode17']

    can be rewritten as:

    //div[@class='content-panel']//span[contains(@id, 'textnode')]

    By referencing a stable ancestor and using partial matching, your test objects remain more resilient to changes in dynamic identifiers.

    šŸ¤– AI-assisted response
    šŸ‘ Found it helpful? Click Like
    āœ… Issue resolved? Click Mark as Solution

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    Read through and understand Object Identification, this is vital in order to get TestComplete to identify the correct object you want to interact with.

    In order to resolve your issue, you need to use, if possible, unique property values to identify the object.

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    Hello nfarr7,

    Have you read about 'Selectors'?  If you are using a name map this may be what you need.  There is also an article on conditional name mapping...

    Name Mapping - Selectors
    https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/selectors.html

    Name Mapping - Conditional Mapping Criteria
    https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/conditional-mapping-criteria.html

    If you are running scripts without using a name map then check into the Find, FindChild and FindAllChildren methods.  You can use a Property [Name(s)], [Value(s)] key pair set to return a target object or an array of all child objects you can loop through.

    FindChild Method
    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findchild-method.html?sbsearch=FindChild%20method

    FindAllChildren Method
    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findallchildren-method.html

    PropValues

    A value of a single property or an array of values of properties that the PropNames parameter specifies.

    Values can contain wildcards or regular expressions:

    • The asterisk (*) wildcard corresponds to a string of any length (including an empty string).
    • The question mark (?) wildcard corresponds to any single character (including none).
    • To specify more complicated sought-for patterns for property values, use regular expressions, in the following format: regexp:<pattern>. For example, regexp:gr[ae]y.
    •  The property does not support native regular expression syntax, that is, the syntax provided by scripting languages. Use standard TestComplete (non-native) syntax to specify regular expressions.

    ... If you find my posts helpful drop me a like! šŸ‘ Be sure to mark or post the solution to help others out and/or to credit the one who helped you. šŸ˜Ž