cancel
Showing results for 
Search instead for 
Did you mean: 

FindAll returns blank in log - help!

SOLVED
Highlighted
Contributor

FindAll returns blank in log - help!

Hi All - 

Trying to get back some data when doing the "FindAll" method.  "Find" seems to work fine and prints to the log fine.  Whenever I run FindAll, it does not give me any error - but the log is literally empty.  Can someone point out what I'm doing wrong here?  

 

This works:

function Find() {
Results = NameMapping.Sys.browser.page.nav.Find("contentText", "administrative", 1, 1000);
Log.Message(Results.MappedName);
}

 

This does not work: 

function Find() {
Results = NameMapping.Sys.browser.page.nav.FindAll("contentText", "*", 1, 1000);
Log.Message(Results.MappedName);
}

 

Any ideas? Many thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: FindAll returns blank in log - help!

further to @cunderw 

 

You may need to explicitly convert the items that FindAll returns to an array

function Find() {
Results = NameMapping.Sys.browser.page.nav.FindAll("contentText", "*", 1, 1000).toArray();
for(var i=0;i<Results.Length;i++){
  Log.Message(Results[i].MappedName);
  //you could break early:
  if(Results[I].MappedName=='TableName')  {
    break;
  }
} 
} //I tend to use for(var i=Results.length-1;i>=0;i--) because TC returns the find results from the leaf furthest down the hierarchy first and traverses up and in the majority of cases I want to look from the top level down - personal preference though

-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

12 REPLIES 12
Highlighted
Community Hero

Re: FindAll returns blank in log - help!

FindAll returns an array of objects, not a single object so it doesn't have a property "MappedName", you will have to loop throught the results and print each one of the objects in the array. 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Community Hero

Re: FindAll returns blank in log - help!

further to @cunderw 

 

You may need to explicitly convert the items that FindAll returns to an array

function Find() {
Results = NameMapping.Sys.browser.page.nav.FindAll("contentText", "*", 1, 1000).toArray();
for(var i=0;i<Results.Length;i++){
  Log.Message(Results[i].MappedName);
  //you could break early:
  if(Results[I].MappedName=='TableName')  {
    break;
  }
} 
} //I tend to use for(var i=Results.length-1;i>=0;i--) because TC returns the find results from the leaf furthest down the hierarchy first and traverses up and in the majority of cases I want to look from the top level down - personal preference though

-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

Highlighted
Contributor

Re: FindAll returns blank in log - help!

@RUDOLF_BOTHMA  @cunderw 

Thank you for the replies.

 

@RUDOLF_BOTHMA - I tried that code - and it seems go through without any errors or warnings, but the test log is empty.

Highlighted
Community Hero

Re: FindAll returns blank in log - help!

That would seem to suggest that FindAll isn't finding anything at all.  You may need to revise your find criteria

 

What does Log.Message(Results.length) tell you? if you put it in after the .toArray() ?  I would expect there to be a log entry "0"

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
Highlighted
Community Hero

Re: FindAll returns blank in log - help!

OR!!!!!

The items you are finding don't have a Mapped Name... if they are not mapped in NameMapping, then MappedName is blank.

So... is it that the log has NOTHING?  Or is the log showing a lot of rows of nothing?


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: FindAll returns blank in log - help!

Thanks for the reply.

 

I do have objects Name Mapped for sure on the screen in question and Parent element in question.

 

if I run 


function Find() {
PropNames = ("contentText")
PropValues = ("*")
Results = NameMapping.Sys.browser.page.nav.FindAll(PropNames, PropValues, 1, 1000);
Log.Message(Results.length);
}

 

I get a Log message of 53.

 

There is a possibility that I am getting an array of empty values?  Is there any console in TestComplete to show whats going on? It's a bit difficult to see where this is failing, especially when I am not getting errors.

Highlighted
Community Hero

Re: FindAll returns blank in log - help!

Not a console as such, but if you drop a breakpoint, you can add a watch and inspect the value of "Results" to see what it actually is returning.

On MappedName.

You may have mapped items... but are they necessarily the items that come back from the FindAll?  The reason I say that is because you CAN map something that is not necessarily an immediate child of the parent.

Say, for example you have THIS mapped


NameMapping.Sys.browser.page.nav.panel1

 

There is an option on that panel1 object called "Extended Find".  What that means is that panel1 might not actually be a direct descendent of nav.  There may be other objects in between nav and panel1.  FindAll finds all objects, but it doesn't necessarily mean that the objects it finds are mapped objects.

If you open your object browser and look at your page and at that nav object, what objects are there?  Can you screenshot the property list of one of those objects?  

 

Again... do you get just a log of 53 blank lines? or does it just give you a log of nothing at all?  Have you tried to do Results[i].FullName and see what that returns?  Maybe that will help us understand better what's going on.


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
Community Hero

Re: FindAll returns blank in log - help!

With @tristaanogre :

 

TC returns everything in the page layout hierarchy - which you can see in object brower - up to the specified depth in your FindAll.  It doesn't look at your child name mappings or aliases when it does the FindAll. That means you could find lots of objects that have nothing to do with your mappings and therefore they will have empty name mappings.  Because of the way TC searches the object hierarchy, rather than mappings, you may have to increase the search depth to find the objects you are looking for. So your current code only brings back the direct children of NameMapping.Sys.browser.page.nav.  Try

 

Results = NameMapping.Sys.browser.page.nav.FindAll("contentText", "*", 10, 1000).toArray();

You may have to tinker about with that depth so you don't get too many tiers.  That would make things really slow.  You can also improve the search properties and names to bring back a smaller set.

 

P.S. You can right click the Aliased/Mapped item and "Show in Object Browser" to easily track them down


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
Highlighted
Occasional Contributor

Re: FindAll returns blank in log - help!

Hi @cunderw I'm running into a similar issue as mentioned by the OP. My question relating to that and your response is, how can I loop through the results and print each one of the objects in the array? My apologies if this is something basic or beginner; I'm a complete newbie to this and trying to learn by doing & from the TC Academy, Courses, Community Board, etc.

Thanks in advance for any reply or assistance.

 

Cheers,

Allen

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors