Forum Discussion

HirendraSingh's avatar
HirendraSingh
Occasional Contributor
5 days ago

TestComplete mapping issue with similar objects

When I try to map any web objects then TestComplete is not identifying it uniquely using id or name and it will map similar objects together and test fails if similar objects mapped on different pages.

Is there any way to map object using id directly using TestComplete. Currently as a work around I am taking uniquie xpath from inspect element and using it in Name mapping repository but it is time consuming.

6 Replies

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

    As requested -

    Can you provide an example of these similar objects, together with the name mapping you have defined please?

    Otherwise, it's difficult for us to help!

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

    Hello HirendraSingh,

    Mostly I am just going to echo what Hassan_Ballan​ said and toss in a few links....

    TC used only property based identification by default in versions 14.50 and prior.  XPath and CSS Selectors with conditional statements could only be added manually to the name map if enabled.  However this isn't the case now.  Adding an XPath or CSS Selector changes the way objects are identified as you have found.  The fact that you have to add these manually as a work around likely means it was disabled at some point, is not enabled now, or the project was coded without this enabled and you are now going back to refactor.

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

    Name Mapping Selectors:
    https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/selectors.html#update-mapping-criteria-for-web-objects-only

    The most effective stable mapping method I have found is to avoid the use of extended find and always base your mappings from the nearest unique parent object.  In many cases this will require manual intervention. If your pages have many similarly named objects it's just going to take work to make it stable unfortunately,

    • Organizing elements under their respective page objects to avoid cross-page conflicts.
    • Refining Name Mapping properties to use stable identifiers like id, name, or meaningful attributes.

    If your pages are well structured and objects named this isn't as much of a hassle.  TestComplete does a pretty good job of assigning object properties useful for object identification.  Work closely with your devs so your pages are 'testable' and have solid names for automation.

    I am on the fence about 'Self Healing'.  I turn it off.  Some prefer to use it because a script will go ahead and run if the id can be changed during runtime to something that works.  

    The use of TestComplete's AI features can be a big help here as well.  These will let you find objects visually instead of by code.

    ... 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. 😎

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

    Have you checked if your project is configured to use XPath? It typically is by default — you can confirm this under Tools > Options > Engines > Name Mapping, and ensure that “Use XPath and CSS selectors for web objects” is enabled.

    TestComplete generally does a good job with object mapping. It often maps multiple XPath expressions using an OR condition — if it can't interact with the object using the first XPath, it tries the next one in the list, and so on, until it either finds a match or fails completely.

    Also, keep in mind that by default, object mapping in TestComplete is based on a pairing of the Page URL and the element. Are you referencing all your elements under a single page URL object? If so, that could explain why similar objects across different pages are being treated as the same — TestComplete may be assuming they're part of the same context.

    For more complex or dynamic applications, manual mapping — like you're currently doing — is sometimes necessary. But to reduce effort, consider:

    • Organizing elements under their respective page objects to avoid cross-page conflicts.
    • Refining Name Mapping properties to use stable identifiers like id, name, or meaningful attributes.

    If you want to dive deeper, SmartBear’s community blog has a great article on scaling TestComplete testing for complex apps like Salesforce, which covers advanced mapping strategies and tips:
    Pro Tips from the SmartBear Community: Scaling Salesforce Testing with TestComplete

    🤖 AI-assisted response.
    💬 Was this helpful? Click Like to show appreciation.
    ✅ Got the answer you needed? Mark as Solution to help others find it too.

    • HirendraSingh's avatar
      HirendraSingh
      Occasional Contributor

       “Use XPath and CSS selectors for web objects” is enabled. In my Project.
      Also "Organizing elements under their respective page objects to avoid cross-page conflicts.": For this I am using variables to pass URL and mapping objects in single page only as we need to check our application on multiple environments, so want to change it frequently. So using variable for each page after it is mapped is what time consuming as there are many pages in our application.
      Any help here is appreciated.

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

        Hi HirendraSingh​,

        Have you had a chance to review the article I referenced about scaling TestComplete for complex applications like Salesforce? Is your application similarly complex in terms of dynamic content and page structure?

        Also, did you pay close attention to the caching issues discussed there — both at the page and element level? 

        Since we don’t have detailed information about your specific application, it’s a bit of guesswork on our end. To assist you effectively, could you please provide a detailed, isolated example illustrating one of the problematic objects? Including screenshots or snippets of your current Name Mapping setup would be very helpful.

        Looking forward to your response!

        🤖 AI-assisted response.
        💬 Was this helpful? Click Like to show appreciation.
        ✅ Got the answer you needed? Mark as Solution to help others find it too.

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

    Can you provide an example of these similar objects, together with the name mapping you have defined please?

    If you can provide a screenshot like this, it will be helpful.