Ask a Question

Using FindChildEx with regexp

SOLVED
hrothrock
Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: Using FindChildEx with regexp

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

9 REPLIES 9
tristaanogre
Community Hero

Re: Using FindChildEx with regexp

Note that in all of these, you're not actually giving a timeout.  It could be that one of them works but the object is not immediately available at the time you execute FindChildEx.  There are 2 parameters after the depth parameter that include a "refresh tree" (default to false) and a "timeout" (defaults to 0).  You might want to look at this.

 

Also... contentText might not be the best choice of property to check, at least not alone.  Is there an ObjectType property that you can add for additional searching?

 

Also, in this case, the regex systax is the non-native (see https://support.smartbear.com/testcomplete/docs/scripting/regular-expressions.html) so double check what syntax you're using.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
hrothrock
Contributor

Re: Using FindChildEx with regexp

I will try adding a timeout. In all the documents I have looked at (including the one you attached) I found the explanations to be very confusing but what I got out of them was that when using the Find methods, I should be using the non-native objects.

 

There are object types on our objects but they are almost all 'Panel'...

tristaanogre
Community Hero

Re: Using FindChildEx with regexp

You can include the "className" property as well.  

 

Basically, just like NameMapping, the various Find functions are more efficient, more reliable, if you expand the list of properties you're using.  Searching via one property, especially contentText, can bring back more than you want (contentText includes text from the current DIV as well as all DIVs it contains so that's why you're getting some of what you're getting).  So, adding other properties (like className, ObjectType, etc), can help narrow the search parameters.

 

The first and second parameters of FindChildEx can either be single strings (like you have) or arrays of strings... I'd look into creating arrays and searching that way rather than messing with RegEx, ESPECIALLY since contentText has the problem I've mentioned above.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
hrothrock
Contributor

Re: Using FindChildEx with regexp

I have been looking through the properties that are available to me and because of the way the pages are being built I don't have a lot of options as far as using another property. The reason I am using content text at that level is because I need that level to get to the checkbox. If I use class name, all of the objects on the level I am looking at have the same class name, so it will still rely on the content text to be different and it will still find the wrong object unless I use regexp. In addition, other objects on nearby levels have very similar class names, such that I would have to wildcard out the difference because it could be dynamically generated as the page is built. If I use other properties, I am still having to rely on the name on the page, so I will continue running into the need for regexp. I wasn't using the optional parameters in the method because I agreed with the defaults and had no need to change them (to me it looks like the refresh tree default is true). The timeout is not working, and couldn't be the issue because I am working on the code with the page open so there is nothing to wait for.

tristaanogre
Community Hero

Re: Using FindChildEx with regexp

I didn't mean "use a single other property" but more on the lines of "use a combination of properties".  That's actually the key to good object identification.  So, let's say include "contentText" but perhaps add "className" and "ObjectType" or some other combination.  If you're looking for a specific component, there has to be something that makes it unique otherwise the software would blow-up as well.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
hrothrock
Contributor

Re: Using FindChildEx with regexp

Yes, I understood. My issue is that when I am working with a certain level of objects, almost all of the properties are exactly the same as the other objects at that level so it will not give me more uniqueness to select more properties that are the same as all the other objects at that level. 

hrothrock
Contributor

Re: Using FindChildEx with regexp

The coders use indexes, which I do not find extremely helpful when trying to write a script to be used later. It is less user-friendly to have to look at the object browser every time you want to use a routine, rather than just input the name you see on-screen that you want to use.

tristaanogre
Community Hero

Re: Using FindChildEx with regexp

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

hrothrock
Contributor

Re: Using FindChildEx with regexp

Yep, I think that's going to have to happen (where the devs add a unique attribute for QA). We are heading down that road, hopefully soon. I'm trying to get my head wrapped around the CSS properties and things like that now. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: