Ask a Question

How can I generalize e.g. buttons so that they were found also if the name of the button has changed

Occasional Contributor

How can I generalize e.g. buttons so that they were found also if the name of the button has changed

I have an application that generates some data. Then I want to check this data within a web page. Therefore I navigate to the page and press a button where I should get the data.
The problem is that the name of the button contains the number of the generated Data.
E.g. at first run the button is named "GetData(1)", at second run "GetData(2)" and so on.
Also during test I can not control how often the button is pressed from others.
When creating the Keyword Test and no new data where created meanwhile execution is working, but if some more data are created it does not work anymore because TC searches for the old button name.
I tried wildcards within the name mapping of the button but then also the old button is not found.
I also tried wildcard in the naming of the button but this also does not work.
So how can I solve that problem that the correct button will be found?
The problem is that we have more web pages with similar behavior.
So how can I generalize such buttons so that they were found also if the name of the button has changed?
Thanks for your help.

Super Contributor

Are you able to provide a screenshot of your mapped object? How you've named and identified the button in TC? For example,



Occasional Contributor

The button in the UI is displayed as e.g.  "AlleTest2 (983)"  -so the name of the button is "AlleTest2" and the counter is at "983"

The Keyword Test is like 
Item: "buttonAlleTest2983" and operation "Click Button"

The Obcect is found as

The Name mapping is something like
xpath //OL[@class='k-group-start']/LI[2]
xpath //button[.='AlleTest2 (983)']

When the button name changed and the testexecution fails TC sometimes displays an "intelligent fix" but then it just uses the actual button name, but this does also not help for future because at next test it could be again wrong.

Super Contributor

You can use Wildcards in Name Mapping, or Regular Expressions. For example,


Will match, where ObjectIdentifier equals "sports_jpg_size_100" or "sports_jpg_size_500" etc.

Occasional Contributor

The strange thing is that i only can see and add Xpath in my name mapping for this button and if i use the following entries in name mapping
xpath //button[.='AlleTest2*']
instead of the original //button[.='AlleTest2 (983)']
it is still not working and the test  with "983" does also not work anymore

Super Contributor

Ah XPath! See Finding Web Objects Using XPath Expressions. You can also use XPath standard functions like contains, starts-with and others that may let you create more flexible XPath expressions.

Community Hero



the button is named "GetData(1)", at second run "GetData(2)" and so on.

[Out of scope] Welcome to the beautiful world of modern non-testable web applications created without design and using tools that no QA (QA in its initial meaning, but not QC, tester or test automation engineer) would ever approve. If you like a risk, you may also order a beer to all those who approved the concept and tooling for this project. (But I am really doubting that such process was even thought of.)


Your best approach is to demonstrate to the management that tested web pages do not have semantic markup (i.e. web elements do not have stable and unique identifiers) and insist that developers must provide these identifiers. To say the truth, the chances that management will support you are low. So you should at least demonstrate them a problem and warn them that due to the absence of stable and unique identifiers for web elements on the page the process of automated tests creation will be slow and obtained test code well might be less stable, reliable and supportable than if the page has semantic markup.


Now to the business. The fact that TestComplete names the button as AlleTest2(983) means that this button provides no identifiable information and TestComplete identifies it by it's ordinal number among other buttons on the page. I really hope that when this button is clicked, web page just re-generates it but not makes the previous button invisible and creates a new one. If the latter scenario is the case, this means that your web page severely leaks resources and this must be corrected.


Anyway, as the sought for button does not provide any identifiable information, you must investigate the overall page objects hierarchy using the Object Browser and find parent, child or sibling objects that can be identified. Then your test code should first search for such object and then use it as a starting point for the button search. (I.e. you will search for the button not from page root like it is now but from this intermediate object.)

For example:

-- Your page may contain a div element with class name that contains 'dataSection' and the sought for button is a child of this div -- search for this div first;

-- Then, if this div has two child div elements, both without any identifiers, but the first div contains the button of interest and another div with class name 'dataContainer', then search for this div with the 'dataContainer' class name;

-- Finally, get the parent of the found div and using this parent as a search root, search for any button. As the sought for button is the only child button of the parent div, the found button should be the one that you are looking for.


  /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

I was now able to solve the problem:
a) not the best solution
installing/using the intelligent quality ad on for TestComplete:
This leads to the situation that during testexecution the button first can not be found and then (during execution) the adon tries to find a "similar" button (and this then works - the correct button will be found).
Same behaviour for other buttons with the "same naming problem".
But the execution slows down and on the other hand at the end of the test I get some warnings (yellow flags) tthat the bttons could not be fonnd. So this is not an optimal solution.

b) in this case the better solution:
I was able to solve the Problem using xpath (unfortunately i am not allowed to paste the full path so i sometimes used ... instead of teh correct naming) like:

In this example the "kendo-buttongroup/button[2]" means the button ist the second from the left in the class mentioned before in the x-path.
As I am not a programmer how did I get this information:
I used crome as web browser.
At the web page where the button is displayed I selected the button - pressed right mouse button and the inspect.
Then the developertoools open and the section of the button is marked.
Now I click  (right mouse) on the marked section in the devtools and select copy and then either "Copy X Path" or "Copy Full X Path".
After that I paste that to the name mapping of my button and put it at first place.
That means, when you click in TestComplete on the teststep where the button is metioned (like GetData1 - as TC did not handle the brackets in the naming) and click right mouse button then you can select "show object in name mappind editor"
One more comment:
When openign the developertools and the "button" was marked I sometimes could see that the content was changing.
So I needed to start the "Copy X Path - action" 2 times to get a working result that solved my proplems.
Nevertheless maybe there is a better solution using wildcards in X-Path with naming. If somebody knows it, please comment it also here.
Thanks everybody for your comments and support.

Occasional Contributor

I now also got an official information from Smartbear (I also created a support ticket) at 18. Nov. 2022:

"We would like to suggest that you can’t use X-path namemapping with wildcards."

I also asked them if it is planned for further versions, but did not get an answer (i asked them directly after I got the information).

Showing results for 
Search instead for 
Did you mean: