Pagination every 20 loops go next page searching good workaround

HI
I’m working on an automation that after 20 loops clicks the “next page” button and continues with the work.

Currently I have to write numerous IF to predict all possible pages and it’s hard.

IF loop = 21
click button next page

IF loop = 41
click button next page

IF loop = 61
click button next page

IF loop = 81
click button next page

I would like to know if there is a simpler solution to perform a click/action after 20 loops (at loops 21 - 41 - 61 - 81 - 101 - 121 and so on) so as to avoid having to write many IF for each possible page.

Thanks for suggestion

Hi,

• If you’re unknow xpath, please refer Loop action to next elements in page - #2 by Starbucks
• Simplest solution, change number of records per page to maximum.
• Understand Data Flow Control using loops: White / For, If / Else / Else if, GotoIf, Break / Continue.
• Investigate properties of elements (page 1, page 2…) to find the xpath formula

Example: See photo attached.

• Pagination: 20 records
• Page 1-> Page end: Locator of Customer Code cell:
Row 1: xpath=//div[@role=“row” and @row-index=“0” and @aria-rowindex=“3”]/div[@col-id=“cust_code”]/div
Row 2: Same above with parameters: row-index=“1” and @aria-rowindex=“4”

Row 20: row-index=“19” and @aria-rowindex=“22”

The formula is same for page 1–> page 2 → page end…

PSEUDOCODE: Data flow control

i = 0 // define parameter
j = 0
While (true)
{
j = 3 + i;
xLoc = ( xpath= //div[@role=“row” and @row-index=“\${i}” and @aria-rowindex=“\${j}”]/div[@col-id=“cust_code”]/div )
If (element xLoc presented)
{
Do action…;
i = i + 1; // next row on current page
}
// Each page: maximum 20 records exist: row-index={0,1,…19}. Not present: row-index = 20
Else If (next page button presented)
{
Click next page button; // next page
i = 0; // first row on current page
}
Else Break // last page: exist loop
}

1 Like

At this time i used this if with multiple conditions

IF

\${!TIMES} == 21 || \${!TIMES} == 41 || \${!TIMES} == 61 || \${!TIMES} == 81 || \${!TIMES} == 101 || \${!TIMES} == 121 || \${!TIMES} == 141 || \${!TIMES} == 161 || \${!TIMES} == 181 || \${!TIMES} == 201 || \${!TIMES} == 221 || \${!TIMES} == 241 || \${!TIMES} == 261 || \${!TIMES} == 281 || \${!TIMES} == 301 || \${!TIMES} == 321 || \${!TIMES} == 341 || \${!TIMES} == 361 || \${!TIMES} == 381 || \${!TIMES} == 401 || \${!TIMES} == 421 || \${!TIMES} == 441 || \${!TIMES} == 461 || \${!TIMES} == 481 || \${!TIMES} == 501

CLICK NEXT PAGE BUTTON

You can try: If ((\${!TIMES}-1)%20)==0 then Click next page button

Explanation: The operator % returns the remainder left over when one operand is divided by a second operand

1 Like

Thanks for the solution