cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Magpie_Rob
Frequent Visitor

click download link in Dynamic table

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. 

Magpie_Rob_0-1626812895031.png

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

Magpie_Rob_1-1626813187541.png

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

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):

tkuehara_0-1626817579892.png

  1. The Javascript action will be used to count the number of rows;
  2. As JS action returns a text type, you'll need to convert to number before using it in the loop action;
  3. Finally, the loop action will iterate from 0 to Result-1 and store the value at the variable %i% which will be the dynamic row selector. This way you can have a single "Click link on web page" action inside the loop action clicking at the links on each table row.

View solution in original post

9 REPLIES 9
tkuehara
Super User
Super User

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?

Magpie_Rob
Frequent Visitor

Hi @tkuehara thanks for responding. not sure which part of the element selector you mean but I have included the below 

Magpie_Rob_0-1626815243634.png

 

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:

tkuehara_0-1626815862441.png

 

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. 

Magpie_Rob_0-1626816906974.png

 


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.

Magpie_Rob_0-1626816372248.png

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):

tkuehara_0-1626817579892.png

  1. The Javascript action will be used to count the number of rows;
  2. As JS action returns a text type, you'll need to convert to number before using it in the loop action;
  3. Finally, the loop action will iterate from 0 to Result-1 and store the value at the variable %i% which will be the dynamic row selector. This way you can have a single "Click link on web page" action inside the loop action clicking at the links on each table row.

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... 

Magpie_Rob_0-1626899227767.png

 

is this what would be causing my flow to fail at the end? 

Magpie_Rob_1-1626899503290.pngthanks 

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 😄

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,881)