When using the FindAll method I am getting the runtime error - Object not a collection. This only occurs on certain Windows 10 machines and only when using specific scripting languages.
This is done using a new project and using the FindAll example from the help file. Does anyone have an idea what could be causing this?
All PC's are running:
Windows 10 Pro, Version 1903, Build 18362.592
Solved! Go to Solution.
@Marsha_R It only works when stepping through the code if you switch to the locals tab and expand the actual object that is causing the error. If you don't expand it, or are viewing the call stack, watch list or breakpoint tab it will still show the error. I know all the ways to get around any timing issues, I've tried them all and unfortunetely nothing works.
I just need to put this down to the fact I'm using an older version of TestCompete and it's not going to work forever. Some Windows/third party update is bound to cause issues sooner or later, might be time to finally upgrade.
Your TestComplete version is a little behind. Can you try loading the latest version on one of the machines where it doesn't work and see if that fixes it? It may already be patched.
Be careful and use a separate copy of your project when you do this. Tests that are converted to a higher version of TC are not backwards compatible, so you don't want to lose your 12.1 copy.
It would be helpful to see the code where the error is occurring.
As a note, for FindAll, it returns in a safe array format which is not compatible with the JScript engine (which is what the C++ and C# script translators use). See https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findal...
Why it works 100% on two machines and not on the other two I'm not sure. But, generally speaking, you need to make sure you are using the proper type of array when using the result.
In any case, please post a copy/paste of code that generates the error, indicating the line on which the error occurs, and we can perhaps help you further.
OK... so... call me a nitpicky person... but you gave me a screenshot of the sample code from the help.... That doesn't necessarily mean that the code you have in TestComplete that is generating the error actually is the same code.
Please copy and paste your ACTUAL code that is generating the error as I can pretty much assure you that the example is accurate.
It's literally that sample code copied and pasted into a new project. I know the code is fine as it runs on some machines, what I can't understand is why the error is shown on some of the others:
var p, w, textBoxes, i;
// Obtain the Notepad process
p = Sys["Process"]("notepad");
// Open the Font dialog
w = p["Window"]("#32770", "Font");
// Obtain all edit buttons in the Font dialog
textBoxes = w["FindAll"]("WndClass", "Edit", 5)["toArray"]();
// Log the search results
if (textBoxes["length"] > 0)
for (i = 0; i < textBoxes["length"]; i++)
Log["Message"]("FullName: " + textBoxes[i]["FullName"] + "\r\n" +
"Text: " + textBoxes[i]["wText"]);
Log["Message"]("Total number of found edit buttons: " + textBoxes["length"]);
Log["Warning"]("No edit buttons found.");
Most probably, w was not assigned a reference to the Font dialog window at this line:
w = p["Window"]("#32770", "Font");
Try to replace call to .Window with the call to .WaitWindow and see if it helps.
(I believe that the changed line will be like this:
w = p["WaitWindow"]("#32770", "Font", 30000);
but you should double check the syntax.)
Thanks for the suggestion but no luck with that either.
I've found that if I put a breakpoint on 'w = p["Window"]("#32770", "Font");' and step through it it allows you to get past the 'object not a collection error'.
However, you will then get an 'Object doesn't support this method' error when trying to log textBoxes[i]["FullName"]. Again, if you step into this when debugging it will also get past this error.
It seems that in order to get this to work on these two machines outside of debugging I need to add the following lines:
Still have no clue why I need to do this on these specific machines.
It sounds like timing issues, honestly. You Select the "Fonts" drop down but when you go to assign "w" to the drop down, it's not present immediately and, therefore, you get the undefined. The bits of code you added in add an implied "delay" to wait for the object to be present before it can perform the action.
So.... instead of
w = p["Window'"]("#32770", "Font");
w = p["WaitWindow"]("#32770", "Font", -1, 10000)
I think you may need to do something similar for later on as well.
Get properties of a web page element
Compare images using the Region Checkpoint
Compare HTML table with Excel file and correct data in Excel file
How to execute remote test and obtain results via Test Runner REST API