Hello!
I'm a Power BI Dev who has ended up with some power automate in his lap! and I'm hoping the power automate community is just as good as the BI one!
I'm trying to set up a flow to automatically download files off a supply portal. I got to the part where we actually need to click download.
so in the table in the screenshot, I need to click on the blue items which in turn downloads a .xlxs file.
I have a kind of dogy work around at the moment which I have included below, which basically uses a load of if statements
Is there a way to iterate this based on the number of UI elements within the table and perform the downloads?
My next step is to get all the details from the separate sheets (they have the same structure) and upload them to a SQL DB. (I'm sure there will be more posts).
Thanks
Rob
Solved! Go to Solution.
Perfect! Thanks.
I can see the link goes in the same first div in the same first column (td element) on each row. The selector should work then. Just add the loop, generating the variable %i%.
In this case (dynamic table) you can't perform a fixed loop. I'd go for a JS solution to count row numbers and then use it to loop each row in the table (don't know if you are familiar to JS though).
From what I can see, this JS script should work (unless you have iframes in the page):
function ExecuteScript() { var myRows = document.querySelectorAll('table#sharedreport-external-details-table > tbody > tr'); var count = myRows.length; return count; } |
Here's how your flow should look like (simplified version, and you can ignore the Launch new Chrome - I just did it to generate the %Browser% variable):
Hi @Magpie_Rob
Welcome here!
Yes, you can iterate UI elements by changing them to a dynamic one.
Could you provide a print from your element selector?
Hi @tkuehara thanks for responding. not sure which part of the element selector you mean but I have included the below
Oh dang! I forgot asking you for the page's HTML structure haha but I'll assume the dynamic part should be the rows.
In this case, you need to customize your selector from:
html > body > div:eq(3) > div:eq(0) > div:eq(1) > div > div:eq(1) > div:eq(5) > div > div:eq(1) > div > div > div:eq(1) > table > tbody > tr:eq(0) > td:eq(0) > div:eq(0) > a
To:
html > body > div:eq(3) > div:eq(0) > div:eq(1) > div > div:eq(1) > div:eq(5) > div > div:eq(1) > div > div > div:eq(1) > table > tbody > tr:eq(%i%) > td:eq(0) > div:eq(0) > a
If your table always have the same size (4 rows) then you can execute a simple loop from 0 to 3:
Not sure how to tell you the page's HTML structure (sorry I'm a complete novice). But I have included my best guess screenshot below.
I did see this solution in another post! with the %i% but this doesn't seem to work in my flow! see the error message I get below.
and the table size in this is dynamic I'm not sure on the maximum number of rows hence wanting the iterator to work and not have to input 50 if statements.
Thanks
Perfect! Thanks.
I can see the link goes in the same first div in the same first column (td element) on each row. The selector should work then. Just add the loop, generating the variable %i%.
In this case (dynamic table) you can't perform a fixed loop. I'd go for a JS solution to count row numbers and then use it to loop each row in the table (don't know if you are familiar to JS though).
From what I can see, this JS script should work (unless you have iframes in the page):
function ExecuteScript() { var myRows = document.querySelectorAll('table#sharedreport-external-details-table > tbody > tr'); var count = myRows.length; return count; } |
Here's how your flow should look like (simplified version, and you can ignore the Launch new Chrome - I just did it to generate the %Browser% variable):
Hi @tkuehara thanks so much this is very nearly working!
so I can't seem to put the result as result -1 in the loop... am I missing something...
is this what would be causing my flow to fail at the end?
thanks
Rob
Hi @Magpie_Rob, glad it is almost there!
Yes, it is the cause of the error at the end. You need to put the number inside the "%" signs: %JSResult - 1%
thanks @tkuehara thats all now working, amazing! thanks for all your help! Kudos and Accepted solution incoming
Great! Tks buddy 😄