RegasQA
6 years agoNew Contributor
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:
- You are using Project.Variable and not a ProjectSuite.Variable.
- 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%'].
- (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')]).