cancel
Showing results for 
Search instead for 
Did you mean: 

Iterating through items

SOLVED
Highlighted
Occasional Contributor

Iterating through items

Hey everybody, me again

 

This time, my issue is that I have to iterate through a series of objects.

The objects have objectID '0', '1', '2', and so on, but the amount of objects is not fixed.

 

What I tried is creating a Project Variable, and go for

      while(Aliases.browser.pageCockpit.frameUserMenu.panelIterative.Exists)
      {
        Aliases.browser.pageCockpit.frameUserMenu.panelIterative.Click(15, 20);
        Project.Variables.panelIterativeIdentifier++;
      }

And set the ObjectID identifier in namemapping to panelIterativeIdentifier as well.

It just doesn't work, it keeps going for the object with the ObjectID of 0. What am I doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Iterating through items

Hello,

 

These are my ideas for solving your problem:

 

1) Try using regexp using the .find() methods, with this method you can only get the items you want inside the table, or maybe an object

 

Doc: https://support.smartbear.com/testcomplete/docs/reference/misc/regular-expressions.html

 

2) Write your own JavaScript code to select the item you want to have inside the data object. Run this script with TestComplete.

 

Doc: https://support.smartbear.com/testcomplete/docs/app-testing/web/general/common-tasks/javascript.html

 

3) it's better to use "do while" instead of "while" in your situation.

 

4) Download all posts from findxxx() -> debug object -> use e.g. javascript .filter() on it and filter the items you only want to have.

 

Sample function:

var filteredData= findElements.filter(function(val) {
        return dataObj.indexOf(val) == -1
});

 

View solution in original post

9 REPLIES 9
Highlighted
Community Hero

Re: Iterating through items

Hi,

 

What if you search for all those objects via the .FindAllChildren() method and then iterate through the returned array?

 

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

Re: Iterating through items

Hi,

 

@AlexKaras is right.

 

To be more specific I am sending You an online article about looping through arrays of objects.

 

https://stackoverflow.com/questions/16626735/how-to-loop-through-an-array-containing-objects-and-acc...

Highlighted
Occasional Contributor

Re: Iterating through items

Hello Alex,

thank you for your reply.

I've tried working with .FindAllChildren(), but due to the way the site is set up, this is causing major issues, detecting objects that I do not want to iterate through as children.

 

The possible solution I've described in my OP is the only way I could see this working, but it simply doesn't work.

Highlighted
Community Hero

Re: Iterating through items

Let's see the Advanced version of Object Spy results of the panel with all those objects in it please.

Highlighted
Community Leader

Re: Iterating through items

Hello,

 

These are my ideas for solving your problem:

 

1) Try using regexp using the .find() methods, with this method you can only get the items you want inside the table, or maybe an object

 

Doc: https://support.smartbear.com/testcomplete/docs/reference/misc/regular-expressions.html

 

2) Write your own JavaScript code to select the item you want to have inside the data object. Run this script with TestComplete.

 

Doc: https://support.smartbear.com/testcomplete/docs/app-testing/web/general/common-tasks/javascript.html

 

3) it's better to use "do while" instead of "while" in your situation.

 

4) Download all posts from findxxx() -> debug object -> use e.g. javascript .filter() on it and filter the items you only want to have.

 

Sample function:

var filteredData= findElements.filter(function(val) {
        return dataObj.indexOf(val) == -1
});

 

View solution in original post

Highlighted
Community Manager

Re: Iterating through items

Thank you Community for a lot of great suggestions on that. 

Hi @underqualified , were you able to find a solution? Perhaps, some of the suggested approaches worked for you. 


Sonya Mihaljova
Community and Education Specialist
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: Iterating through items

I'm not sure yet,

I'll be attempting the suggested solutions and then mark whatever ended up working as the answer!

Highlighted
Community Manager

Re: Iterating through items

Hi @underqualified , any progress with this? Do shareSmiley Happy


Sonya Mihaljova
Community and Education Specialist
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Manager

Re: Iterating through items

Hi @underqualified,

 

Let me mark Wamboo's suggestion as a solution. If you find your own solution, please share it with the community.

 

 

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
A new challenge is here!

Create a function to drag one element to another for the TechCorner tag!

Will you dare to take the challenge?


Scripts created in July:
- Passing custom command-line arguments as a test parameter
Top Kudoed Authors