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