IF(ELSE) Statement & Loop

if (WebUI.verifyElementPresent(findTestObject(‘Page_EXP Correction (Some field, All time open)/img’), 3, FailureHandling.OPTIONAL)) {

for (def row = 1; row <= findTestData('ExportBillInput').getRowNumbers(); row++) {

WebUI.setText(findTestObject('Page_EXP Correction (Some field All time open)/input_Exp Serial_p_t04'), findTestData(
        'ExportBillInput').getValue('Exp', row))

WebUI.selectOptionByValue(findTestObject('Page_EXP Correction (Some field All time open)/select_202020192018201720162015201420132012_b0c8c4'), 
    findTestData('ExportBillInput').getValue('ExpYear', row), true)

WebUI.click(findTestObject('Page_EXP Correction (Some field All time open)/a_Search'))

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/input_Bank Bill No_p_t38'), 
    findTestData('ExportBillInput').getValue('BillNumber', row), FailureHandling.CONTINUE_ON_FAILURE)

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/input_Bank Bill Date (DD-MON-YY)_p_t39'), 
    findTestData('ExportBillInput').getValue('BillDate', row))

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/textarea_Remarks_p_t40'), 
    Keys.chord(Keys.CLEAR))

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/textarea_Remarks_p_t40'), 
    'Bank Bill Number & Date Included')

WebUI.click(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/a_Apply Changes'))

} }

else {

WebUI.refresh()

???

}

Here in ELSE statement after REFRESHING the page in the ??? I want to start the process of looping again with a simple condition that if the last value of [def{row}] is for example 10, [but not equal to 1] it should be now 9. Alternatively if row <> 1 then row = row-1.
How can I do that? Please help.

Not quite sure if I understand, but maybe like:

WebUI.refresh()
def max = findTestData('ExportBillInput').getRowNumbers() > 1 ? findTestData('ExportBillInput').getRowNumbers() - 1:  0;
for (def row = 1; row <= max; row++) {

the above is a tertiary statement–like an if-else statement on one line.

Another consideration is a while loop in which you don’t have an else clause but just keep on reducing your row value (findTestData(‘ExportBillInput’).getRowNumbers()) by one.

Just a note that you may be missing the zero row since you start your loop at one so you should check that within your results.

for (def row = 0; row < max; row++) {

@grylion54

If you please look at the beginning you will see that there’s a loop. And it will stop if an element is not found in the web page then the web page should refresh to bring back that element. During this process of looping/iteration the row variable must have iterated/looped from 1 to any number depending on the quality/volume of data in excel file.
Now when the web page will be refreshed (Upon Not Founding That Element), I want to restart the process of iteration/looping exactly from where it was stopped - 1. But if it gets stopped at the very beginning say in first looping i want to restart the entire process.

Row started from 1 as the first row marked as header

With the code you have shown, you will only have one of either two loops: one if the element is present and one if the element is not present. With my tertiary statement, if the element is not present, this will reduce the number by one if the number of rows is greater than one. If the number of rows is not greater than one, then the number will be zero (and no looping).

If this is not what you are wanting, then you may have to readjust your code some. You can always try it to see if it works.

Thanks for your info. I want to learn a thing from you. Can Katalon detect the last number of row it executed?

For example: Say I have 50 rows of data in excel. And while looping after execution of 5th row’s data it didn’t found the element present. So It refreshed the page. So how can I know that Katalon tried the 5th row’s data last when the element was present? Is there any way to declare a variable or something that can hold the value of last tried or executed row number?

I’m sorry as I don’t know much about katalon as I’m just a beginner.

Finally Resolved It!