Using a for each loop start with the x element of the arrary

Hello,

I want to start with the 30th element of an array. I was following this post for each loop and I think the output index could help me. When I tried to enter a number it gave me an error. Is this the right approach?

Hi.

You can use .Skip() and .Take() to move around in an Array. But, you also need to know the index, so when you exit the loop, it can remember this index, then continue with that item the next time it gets to the loop.

Simply put, you can do this:
For each item in arr.Skip(index)
where index is a variable you used in the Output property of the ForEach. Just make sure the variable is global so it doesn’t reset to 0.

If you are getting an error, share what the error says and what code snippet you are using that caused the error.

EDIT: to start at 30, just set the index variable’s Default value to 29, which is the 30th item.

Regards.

1 Like

Hi @ClaytonM

Thanks for the response! Is this something I do after creating the array? I’m not sure what to put in the Output-Index.forEach

Edit: I get it now, it would be ForEach item in filesList.Skip(29)

1 Like

Yes that is correct. You can simply just start at 29 index.
If you want it to continue where it left off (in case of error handling), then you would need to use the Index property and store the 29 in the default value so it starts at 29, and also change the scope so it is global.

Regards.

@ClaytonM

Follow up question! The application I’m using times out after 900 seconds. Is there a way to set a separate counter to mimic a different mouse click? Have you ever come across an application that automatically logs when there is no activity?

So I’ll start at position 29 in the array, after 10 minutes stop processing to click somewhere else, then resume the array for another 10 minutes.

All the time, early on in my RPA journey. I don’t think a mouse mimic on the page will be very reliable, but you can always just place random Hover or Clicks on the page if you want. Ideally, the reliable and most developer-friendly method would be to have robust workflow component for your application that can see a page is not logged in (or timed out), and perform that action again. - this also allows you to execute the task even if the window is closed on accident. Additionally, you should have robust project design to handle when a page is not loaded correctly that causes elements to fail, so it closes everything, then performs a retry attempt on the current item it was processing.

Being able to detect when the page is timed out or not open and log in again is probably a good solution to this. But, make sure you close all instances of or attach to the timed out window so it doesn’t keep opening a new window and messy up the environment.

Regards.

So is there a way to check if a login window is present? If so, then I could enter the user name and password, then resume processing.

Find Element or Element Exists with a timeoutMS set so it only looks for the element for that amount of time before it moves on to next step.
If you use Find Element, then you can check the element by using the Output property to a variable, and using a condition like this: elementVar isNot Nothing. Element Exists is probably more widely used for this cause it outputs a Boolean.

You can look at the entire window (if the title is different than the other windows), or you can look at the Username or Password textbox, or any other element unique to that page.

I hope that helps.

Regards.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.