For loop syntax and script does not run will for loop present

Hi everyone,

If I place a for loop in my script, the “Run from here” option under right click does not work? I have to run from the beginning. If I take the for loop out, the “Run from here” option works again. Is this caused b/c the for loop is written incorrectly?

Just to make sure, is the following for loop versions correct?

for ( int i = 1; i < 5; i ++) {

 WebUI.verifyElementVisible(findTestObject("ACE Docs/Advanced Search/DP-${i}"));

}

for ( int i = 1; i < 5; i ++) {
String a = toString(i);
WebUI.verifyElementVisible(findTestObject(‘ACE Docs/Advanced Search/DP-’+ a));
}

Looks like you are using a parameterized test object. And that you have the path of the object mixed up with the xpath to locate the object.

Suppose you define your test object named “ACE Docs/Advanced Search/DP”. And suppose it has a parameterized xpath expression //*[@id='my-element-${index}']

To find the element on the page with id=“my-element-2” you would use

findTestObject("ACE Docs/Advanced Search/DP", [('index') : 2])

https://docs.katalon.com/katalon-studio/docs/parameterize-webmobile-test-object-properties.html

1 Like

Hi Harold, it worked, thanks!

1 Like