I have a list of files displayed in a data grid along with other details such as Modified Date and a Download option for each file.
My requirement is to download the latest file, which means I need to identify the row with the most recent Modified Date and then click the Download option corresponding to that row.
Could you please suggest the best approach to implement this in UiPath?
Use Extract Table Data → get grid into “dtFiles” DataTable
Use Sort Data Table → sort by “Modified”, Descending → output “dtSorted” (latest file now in Row 0)
Use Assign activity → latestFileName = dtSorted.Rows(0)(“FileName/UniqueColumn”).ToString
Use Click activity on Download icon → edit selector to reference that row dynamically:
Your selector for Click activity should be something similar to this:
This targets the Download button in the same row as the latest file.
The grid supports sorting, the easiest approach is to sort by the Modified Date column in descending order. Check whether the column header exposes a sort state (ascending/descending) through an attribute. If needed, click the header until it’s sorted in descending order, then simply click the Download option for the first row.
Another way is, extract the table, find the row with the latest Modified Date, and click the corresponding Download button.
adding to the answers above, the part that usually trips people is turning “row 0 in the DataTable” into an actual click, since sorting the DataTable doesnt sort the visual grid. Two ways to solve that
if the grid has clickable column headers, click Modified Date until its sorted descending, then just click Download on the first row, simplest option, no dynamic selector needed
if it doesnt sort, anchor on content instead of position. Get the Modified Date (or filename) text from dtFiles.Rows(0), then use Anchor Base or Find Element to locate that text in the grid, and click Download relative to it. Way more reliable than trying to guess wich visual row is index 0
if its a web grid, another option is skipping the click entirely, grab the download link’s href with Get Attribute or Invoke JavaScript and download directly via http request
You could click the Modified column header and perhaps capture the downward facing arrow as your Validation element (appears), to support automatic Retry and make sure the sorting is as it should be.
After this a Click on the download button for row index 0 should do the trick
A good approach would be to first identify the row with the latest Modified Date, and then use that row to click the corresponding Download button.
You can implement it like this:
Use Extract Table Data to extract the grid into a DataTable.
Convert the Modified Date column to DateTime if it is not already in that format.
Find the row with the maximum date, for example: latestRow = dt.AsEnumerable().OrderByDescending(Function(r) DateTime.Parse(r("Modified Date").ToString)).First()
Get a unique value from that row, such as File Name or another identifier.
Use that value in the selector/target to identify the Download button in the same row.
Click Download and use Wait for Download (or the appropriate download activity) to confirm the file has been downloaded.
If the grid is dynamic, I would recommend using relative selectors / anchors so UiPath finds the Download button belonging to the selected row rather than relying on a fixed row position.
This approach should also work when the number of rows changes dynamically.