Using FindChildEx with regexp
I am writing a function to find a child object based on contentText. The items that I have are named similarly, and in my case I have one called "Dispatch 2" and one called "Dispatch 24". If I use text only to find the child and use "Dispatch 2" as my text, it chooses the Dispatch 24 object, every time. I am trying to use regexp to force it to only match exactly what I type, but I am running into several problems there. For some of the ways I wrote the code, it still finds Dispatch 24 instead of Dispatch 2. For others, it finds no object at all. For yet others, it finds the Dispatch 2 line but in order to find it, must go too many levels deep and then I can't click on the checkbox because it is on the same level as the child object found.
The contentText is:
Dispatch 2
No Jobs Assigned
In some cases, the "No Jobs Assigned" section could be different so I would like to wildcard that part without wildcarding the name of the applicator (Dispatch 2).
I have tried many different combinations in this code with no luck. Here are some that I have tried:
FindChildEx("contentText", "regexp:Dispatch 2", 0)
- finds Dispatch 24
FindChildEx("contentText", "regexp:Dispatch 2*", 0)
- finds Dispatch 24
FindChildEx("contentText", "regexp:Dispatch 2$", 0)
- object does not exist
FindChildEx("contentText", "regexp:Dispatch 2$", 1)
- finds Dispatch 2, at the text node level, 1 level too deep for me to be able to click the checkbox
FindChildEx("contentText", "regexp:^Dispatch 2", 0)
- finds Dispatch 24
FindChildEx("contentText", "regexp:^Dispatch 2$", 0)
- object does not exist unless I change the 0 at the end to a 1, and then I am 1 level too deep
FindChildEx("contentText", "regexp:^Dispatch 2*?", 0)
- object does not exist
How's your relationship with the coders? This is, honestly, what happens when coders write code to just get it done as "elegantly" as possible without considering things further down the pipeline. They, many times, don't think about what some of their "dynamic" object creation does to automation efforts.
See if they can add an attribute to the objects that is a unique identifier. You can then use that attribute as the property for your search.
On those lines, that's something else you can look into. There are properties of onscreen objects that are, themselves, objects with additional properties. css, attributes, etc., are all accessible via TestComplete and can be utilized for object identification.