Forum Discussion

RegasQA's avatar
RegasQA
New Contributor
6 years ago
Solved

Search for dynamic id when creating an item Keywordtest

I have a use case where a new item is created with every test run. Every time a new item is created, a new ID is also generated.

After the item is created, I have to use the ID of that specific item in a search bar. I just can't figure out how to do that. Is there anyone who can help me?

  • In basic scripting, without a dynamic variable, finding and clicking the object is just:

     

    Sys.Browser("*").Page("*").FindElement("//div[.='Refracnadim1 1_Refractionist']").Click();

     

     And if you're using a Project.Variable, it would be something like:

     

    Sys.Browser("*").Page("*").FindElement("//div[.='" + Project.Variable.ListItemX + "']").Click();

     

     

    That being said, it looks like you are using NameMapping within TestComplete, so if it is indeed a mapped object, to click it you would just use:

     

     

    Aliases.browser.pageWHATEVER.label.panelRefracnadim11Refractionist.Click();

     

     

    If this object's xpath has a dynamic property variable that you pass in from another test, you'll need to insure:

    1. You are using Project.Variable and not a ProjectSuite.Variable.
    2. You'll want to update the object in NameMapping to use the Project.Variable in the property criteria (see how here). EX: if your variable name was ListItemX for example, the xpath in the NameMapping would be //div[., '%ListItemX%'].
    3. (Optional) Change the object Name and Alias from panelRefracnadim11Refractionist to panelRefracnadimRefractionist (or similar) for ambiguity and assuming the number changes. This allows you to only need 1 mapped object for every item in the list - assuming you are using the variable approach to pass in the dynamic part of the xpath, and assuming the parent object is mapped appropriately (IE: mapping the container box the list items are in //div[contains(@class, 'practitioner-container')]).

     

5 Replies

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

    When the id is created, capture the value and save it in a variable.  Use that variable for the search.

    • RegasQA's avatar
      RegasQA
      New Contributor

      Thanks for your comment. My goal is that I can run the test automatically and that I don't have to do any manual action with every run. Does this solution work?

      PS. I am just starting with testcomplete ;-)