Exit loop after iterating through dates

I have a automation where i search for a list of dates in a webpage. After the search there good be 1 date or as many as 100 dates. I have the automation fetching the dates but not sure how to get the loop to stop once it fetches the last date. Not sure how i would write the condition to get the robot to exit the loop once it has interated through all the dates. any ideas?

A For Each (or For Each Row in Datatable) automatically stops when there are no more items to loop through. That’s the point to a For Each.

Are you grabbing all the items and putting them into an array or datatable, then looping? Or are you trying to directly grab all the items one by one from the page and then trying to figure out how to stop when it gets to the end?

Reading all the objects into an array then looping through the array is a better option, although the second option can be done.

Look into Find Children - it’ll give you an array of the objects and then you can loop through the array.

@NATHAN_MORA

As you specified you to loop into a list of dates in a webpage

Then you can use While Loop, but you need to check the selectors where you can differentiate between two date elements

So if it you have the tag as 1 or 2, then you can create a element and at the before end of the loop increment that

So here the condition is that take a maximum count and put counter <> maxcounter

Hope this may help you

Thanks

hey @NATHAN_MORA can you provide a screenshot of what you currently have in uipath and also of the webpage you are using? would be good to understand the ask / how you are trying to perform it.

many thanks,

I cant show the webpage because its for work, I bacisally add a name and information in a search bar then a list of names and dates appear, sometimes there will be a list of 1 name or many names. I used a while loop with the condition if index is > 1 then perform the steps. Click on each date on the page using a index +2 variable. it will click the first date and then it will click the second date and so on. im just not sure how to get it to stop once it reaches the last date on the page

after you have searched, do the results get presented in a table? if so i would extract the table using the table extraction wizard, then once you have the table of values extracted to uipath, you can use a for each row to iterate through the table and it will automatically stop once the table it finished

Yes its a table, and i have it iterating through each date just not sure how to get it to stop once it gets the last date

if you have extracted the table from the webpage into a DataTable variable within UiPath, then used a For Each Row to iterate through the rows in the datatable, then the For Each Row will automatically stop after it gets to the last row.

an alternate approach is to use an element exists, so that it checks that the element you want to click on (on this case the date) exists onscreen. if the element exists go ahead and click it, if it does not then use a ‘Break’ activity - the break activity is how you can tell uipath to exit a looping for each