Ask a Question

Dynamic Object Recognition and how to use FindChild in Keyword test

Occasional Contributor

Dynamic Object Recognition and how to use FindChild in Keyword test

Hello, everybody. I am currently assessing TestComplete as a replacement for another Automated test tool which is becoming more and more cumbersome. 

I have only a short time to complete my assessment before I have to return to "real" work and will have no opportunity to continue.

Please excuse me if I am missing the obvious as I am trying to rush things through a bit, sorry.


My boss will not allow us to use User Code as she feels this makes our tests difficult to maintain. Most of our testers have no programming background.

Consequently, I am trying to use Keyword Testing as much as possible. I have two problems, which I believe to be interrelated.

1. We have dynamically generated popup menus. In the other tool, we could supply a variable against one of the properties (text) to find the menu item we wanted to click. In my current keyword tests, I find an apparently fixed index number. I have read this article Testing-with-a-dynamic-built-menu-structure which indicates the use of the FindChild method may solve my issue but I would like a (pictorial?) example of how this would look in TestComplete. Step by step would be great.

I have attached a screenshot of the menu I want to be dynamic.


2. In a similar vein, we often have a number of objects which are dynamically placed on screen, and, in the other tool we can, again, reference these using a property such as caption which is linked to a variable at run time. I have tried using a variable against a property for these objects but at runtime, the value of the variable seems to be ignored and I get the object which was originally recorded. I wonder if FindChild will also solve this problem.

I have attached a screen shot of what I tried but even when I change the variable StepNumber1 the object selected is the same.


Many thanks in advance.


Regards to all.

Community Hero


If I can suggest it, talk to your boss about creating automation scripts by writing code rather than recording elements on the screen.


There are a lot of questions about the choice of working method:

1. how big application do you plan to cover with tests?
When working with keywordTest, you are using a very strong functionality called "NameMapping". Only selected elements should be added to this repository, not everything. Too large a NameMapping file will cause optimization problems in the future.


2. Maintaining and modifying the tests.
If your test scenarios are modified frequently, choose the scripting method with no keyword. It will be easier to maintain and create common libraries.


3. working together on the project and storing files in the repository.
By choosing the scripting method, it will be easier to divide the work into individual team members.


Searching for dynamic elements:

In TestComplete you can choose between different methods .Findxxx(),

One of them is the FindChild() method you mentioned.


An example from Javascript:


// variable
var object = Aliases.program.object;


// in the object you have in the variable you can search for the elementvar searched forObject = object.FindChild("property name", "property value", nesting)


// to the above-mentioned variable I'll save the object to be searched.


Inside the keyword test, Yo can actually write a function to perform some action.


If you open a tab called "Object browser" in TestComplete you will see all the elements that you can potentially map to Aliases and search by .Findxxx()

On the forum, we have already talked many times about topics related to starting work with TestComplete. Please check it:



Occasional Contributor


I have stated that my boss does not want user code. I understand your frustration that I don't just do it with a bit of script but I AM NOT PERMITTED TO and, believe me, I have argued my point frequently.


so what have I tried?

I have found that I can get a child item within a Keyword test into a variable of type object. (Can't prove this works yet due to the point below.)

How do I then click on the object which is now in the variable?


Note that I really want to find the object with the text "New" somewhere within the popup menu which appears after the ClickR on bpa Diagram but, by the time I get back to TestComplete the menu is gone.

If I do a recording it does say Popup menu is the Item/Object but this is not in the name mapper as far as I can see.


I have attached a screenshot of how far I have got but what do I select as the new operation in the keyword test in order to get a click? I have tried On-Screen Action but if I select the variable for it to act upon (which contains the object from the previous Set variable step) it then says that this has no operations.


Screenshot of the test attached.


I did also try to create a new mapping and, somehow, I go a tree down to the first level of menu. however, my menu could be multiple levels (3 currently) and I would like to find the child with a certain name at any point in the tree. SO I suppose I would use FindChild on the root level of the menu.

Also attached a picture of this.


Thanks to anyone who can help.



A lot of Keyword Test operations allow to use variables instead of hardcoded values for their parameters.

You may consider also the Call Object Method operation.

Does this help?


P.S. As you are forced to use Keyword Tests as much as possible, you may consider to create a library of small basic reusable Keyword Tests and use them through out all other tests. I am doubting that such approach will be as effective as the script-based one, but there were messages here that it worked for some people.

Also you may consider to create a helper scripted functions and call them from within library reusable Keyword Tests. (So that unexperienced users are more or less isolated from script code on the one hand but you can get what you need on the other hand.)



  /Alex [Community Hero]
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
Occasional Contributor

Ok, Thanks for your help so far.

As I said - I am trying to avoid using script but I have decided to try this anyway.

Let me explain the problem I have now. I have a three level menu. The first and second levels are fixed in structure, the third is not so sometimes what is now item 2 may be item 1 next time.


So I have tried to implement the findchild but with no success. On the second CLick() I get "Object does not exist".

Please can you indicate what I am doing wrong.

Sub ClickPopup(ItemName,Category )

Dim menuEntry

set menuEntry = NameMapping.Sys.ClientHost.HwndSource_ProcessEditor.ProcessEditor.tabControl.myDiagram

set FoundEntry = menuEntry.PopupMenu
FoundEntry.Click("New|" + Category)
set FoundEntry = NameMapping.Sys.ClientHost.HwndSource_PopupRoot.PopupRoot.FindChild("WPFControlText", ItemName,4,0)


end sub

I know the code is messy and uncommented but at this stage I am just trying things out as quickyly as possible.



Occasional Contributor

Hey - I have found a solution that I worked out with a suggestion from another Forum member.

Sub ClickPopup(Category,ItemName )
  Dim MyDiagram
  Set MyDiagram= Aliases.ClientHost.HwndSource_ProcessEditor.ProcessEditor.tabControl.myDiagram
  Call MyDiagram.ClickR(223, 369) ' Will make this a parameter eventually
  Call MyDiagram.PopupMenu.Click("New|" + Category)
  Dim FoundEntry
  Set FoundEntry = NameMapping.Sys.ClientHost.FindChild("text",ItemName,100) ' ClientHost is the application main window

End Sub


Thanks for the hints and help from rushikesh.

SmartBear Alumni (Retired)

Great news @kevingiles ! Kudos for posting the solution.

Sonya Mihaljova
Community and Education Specialist

Showing results for 
Search instead for 
Did you mean: