Dynamic rows, Click event and open and do rest task

Hi,

I have a situation where i have to click on some hyperlink which is expected to open in new tab and do print and close window.

I am attaching below are the 3 screenshots, where in 1st image u can see i have Onboarding-CDI which is a hyperlink and i have to click on it to open(which is going to open in new tab and after process is done it will close the tab), in 2nd image there is multiple Onboarding hyperlinks and it is expected to be more that 2(i don’t know the count yet), and in image3, situation is like there will be no onboarding hyperlinks.

So to do the job i had wrote a workflow but somehow its not working properly, in case of more than one hyperlinks its returning only one result as per my flow, i am attaching the flow please check.I9_solution.xaml (36.6 KB)

1
image
2
image
3

@indrajit.shah
This is hard to tell, because without web page to debug against, just my mind to follow along - but what it appears to be is the i < counter check when printing.

So, lets say there are 2 elements, 0 and 1. Now, counter = 1 (when it gets to 2, and there is no element i9_element_2, it skips doing a counter = counter + 1 - which makes sense, because there is no element _2)

However, now you counter is 1.

In print section, you check, is i (now=0) < 1? Yes, lets print element_0. Then it does i = i +1 (now i = 1), and it returns to the top of the loop and asks:

is i (now=1) < 1? No, i is not < 1, so the loop exits, and doesn’t print the second element.

So, the condition should be i <= counter or i < counter+1.

At least this is how it appears, as I was not able to test my hypothesis

@sagacity, do you mind editing the same workflow(as per you suggestion) and attach it?

I tried with i < counter+1 its not behaving correctly when there is only one element 0, even when there is only one element on screen its executing 2 times, and i believe that’s the reason its responding correctly when there is one element.

Hey @indrajit.shah,

I have had a look in your workflow.

You are using the while to check the no of hyperlinks you want to click correct me if i am wrong.

Instead of that can you try following approach,

-Do the screen scrapping on the table containing the hyperlinks which will give you a datatable as output.

Then use dt.Rows.count which will give you the no of links on the screen then use this count to iterate through and follow the next step.

@amarasto, ty for you reply.

I tried it but its not returning good results and it didn’t work for me, let me give u the screenshot -

  1. this is the screen from the web

  2. This is the output of the screenscrapping
    image

Hey @indrajit.shah,

Apologies,My Bad do the data scraping instead.
It will give you the datatable then you can check the row count.

@amarasto, even that didn’t work here is the result:
image

Hey @indrajit.shah,

I guess you just need the row count.but here you are writing the scraped result to excel.

yes, but in result the complete data is in one row itself, you can see the web image from the screenshot 1 and output from the data scrapping.

Have you tried scrapping in bot the cases where there is more than one link.

Yes and the result i posted is of multiple hyperlinks events only.

@indrajit.shah You did as I would have. I noticed there is some other issue as well, that the data scraping is not working. Without the pages you are scraping it is impossible to assist as we don’t know what challenges your particular website are presenting.

This may be helpful in turning HTML tables into UI Path DataTables - as it seems like you’re not getting the columns and rows for the datatable properly.

@sagacity, do you mind, if u can just update as per you suggestion in the existing workflow as i attached above, so i can cross verify that i did or followed as per your suggestion.

@indrajit.shah I can, but, I don’t believe that is the complete fix. Though the HTML may not be needed in this case (I may have been thinking about another issue) I’m also seeing something else. Plus, you updated it exactly as I would be sending you - as that is the only place where the “i < counter” condition is and it was just adding a +1.

I can’t properly debug because I don’t have the site to debug against - but you should Debug, Step Into your code and examine the variable states VERY carefully, because now I’m seeing this:

Lets say you have 2 elements, 0 and 1

We start “I9_EventName Element Exists”, this sets dataExist to TRUE as we have I9_EventName_0.

So this satisfies your next IF condition “dataExtist = True”

So, now we go into the DO WHILE loop, keeping in mind that a DO WHILE always executes at least once, then checks the condition (where a WHILE loop only executes provided the condition is TRUE.

So, regardless of what elementExist value is, we run the code.

Current state:
elementExist = FALSE
counter = 0

First, we check the “Element Exists ‘A I9_EventName_0’” Activity which dynamically builds the element condition using “counter.ToString”, so, in this iteration, we are checking for I9_EventName_0 existence, and it exists, so now elementExist = TRUE now and counter = 0

We go to the next Activity, IF elementExist = TRUE, since it is, THEN we ASSIGN counter = counter +1.

The code will NEVER loop to the next element, and if there is only 1 element (element_0) it will always add 1 to the counter making it seem like there are 2. So, on the next line where I have Current State, it will read that whether you have 1, 2,3 or whatever elements. You will always have counter = 1 no matter how many elements because you are setting your elementExist = TRUE which drops it from the DO WHILE loop

Current State:
elementExist = TRUE
counter = 1

Now the DO WHILE checks its condition - is elementExist = False? Nope, it is not - therefore the DO WHILE loop ends and we output: Total Elements Found: 1 (but we are working 0 based, so this is misleading)

Next we continue to the next Sequence, which has the WHILE loop for the i < counter condition:
Current state:
i = 0
Counter = 1

and we’re working with element_0 and element_1

We enter the Print + Save & Close tab section and execute click on eventname, in this case dynamically built to be i9_Eventname_0 (since i=0)

Now we process the print commands, which I wont fully address as it is impossible to determine if it is right or not without the web page - I’m only addressing logic and flow here.

So, it ends with i=i+1

Current State
i=1
counter=1

element_0 processed need to do element_1

But the loop asks, is i < counter, i.e. is 1 < 1? No, it is not, so, even with 1 element left, the loop exits.

If the first section were correct, and you only had element_0 (i.e. counter 0) then this wouldn’t satisfy even once - because 0<0?=FALSE. (but there is a bug in the first case, so, even with just element_0, we will have counter=1 and go through once)

So, the code, no matter how many elements, will only loop once. The reason when we changed the I < counter + 1 it did an extra one was because no matter what happens, no matter how many elements, we go into the WHILE loop with counter = 1 so, we then upped it to 2 meaning no matter how many elements, we would loop twice.

You may not need the DataScraping and DataTable, but, there are some tiny details related to how you are handling your counter, ‘i’ and how that relates to the i9_element_#.

I hope this helps, and points to where you can correct the code - very slowly debug and see the states of the variables. Your initial section of setting up the ‘counter’ value is bugged.