cancel
Showing results for 
Search instead for 
Did you mean: 

Error: Object not a collection

SOLVED
Highlighted
Contributor

Error: Object not a collection

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.

 

ObjectNotACollection.PNG

 

Out of the four machines I've tried it on, two will get the error when using C++Script, C#Script, JScript or VBScript. If using Python or JavaScript it will work. On the other two machines FindAll works correctly for all 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:
TestComplete 12.1
Windows 10 Pro, Version 1903, Build 18362.592

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

Re: Error: Object not a collection

@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. 

 

 

View solution in original post

21 REPLIES 21
Highlighted
Community Hero

Re: Error: Object not a collection

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.

Highlighted
Contributor

Re: Error: Object not a collection

Thanks for the suggestion, unfortunately our maintenance agreement has expired so 12.1 is the latest version I have access to.

Highlighted
Community Hero

Re: Error: Object not a collection

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.


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
Highlighted
Contributor

Re: Error: Object not a collection

Hi Robert, 

 

The error is occuring using the FindAll example from the page you linked. I've highlighted the line:

 

code.jpg

Highlighted
Community Hero

Re: Error: Object not a collection

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.


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
Highlighted
Contributor

Re: Error: Object not a collection

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:

 

function FindEditbuttons()
{
  var p, w, textBoxes, i;

 

  // Obtain the Notepad process
  p = Sys["Process"]("notepad");

 

  // Open the Font dialog
  p["Window"]("Notepad", "*")["MainMenu"]["Click"]("Format|Font...");
  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"]);
  }
  else
    Log["Warning"]("No edit buttons found.");
}

 

 

 

TestProject.jpg

Highlighted
Community Hero

Re: Error: Object not a collection

Hi,

 

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.)

 

Regards,
  /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.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Contributor

Re: Error: Object not a collection

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:

 

code.jpg 

Still have no clue why I need to do this on these specific machines. 

 

Highlighted
Community Hero

Re: Error: Object not a collection

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");

 

replace with

 

w = p["WaitWindow"]("#32770", "Font", -1, 10000)

 

I think you may need to do something similar for later on 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
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare images using the Region Checkpoint

See replies!

Converting UTC TimeDate in an Excel file

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors