18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Trouble with a FOR loop
I have a script that won't continue past a certain point unless the FOR loop section is commented out.
Can you guys see anything that I might be missing?
I've copied what I think are the relevant parts below:
var $arrPicks = new Array();
<<<<< $arrPicks is loaded with a list of random numbers here >>>>>
// ##### Click checkboxes
var $len = $arrPicks.length; // cache the length so it isn't looked up every loop
for (var $j = 0; $j < $len; $j++) {
_checkbox("checkbox[" + $arrPicks[$j] + "]").click();
}
// ##### Navigate to Confirm changes page
_click(_submit(" Confirm changes \u00bb"));
<<<<< Script won't continue below this point >>>>>>
// ##### Verify the number of added keywords
_assertExists(_cell(_table(9), 1, 1));
_assertEqual("0", _getText(_cell(_table(9), 1, 1)));
_assertContainsText("0", _cell(_table(9), 1, 1));
Thanks for any ideas!
Can you guys see anything that I might be missing?
I've copied what I think are the relevant parts below:
var $arrPicks = new Array();
<<<<< $arrPicks is loaded with a list of random numbers here >>>>>
// ##### Click checkboxes
var $len = $arrPicks.length; // cache the length so it isn't looked up every loop
for (var $j = 0; $j < $len; $j++) {
_checkbox("checkbox[" + $arrPicks[$j] + "]").click();
}
// ##### Navigate to Confirm changes page
_click(_submit(" Confirm changes \u00bb"));
<<<<< Script won't continue below this point >>>>>>
// ##### Verify the number of added keywords
_assertExists(_cell(_table(9), 1, 1));
_assertEqual("0", _getText(_cell(_table(9), 1, 1)));
_assertContainsText("0", _cell(_table(9), 1, 1));
Thanks for any ideas!
Comments
I am not sure but using variable index in the array might be posing the problem. Try wrapping the entire thing in a function and calling it.
Try it.. will try using ur loop at my place.
Regards,
Pankaj.
Sorry i forgot to mention that directly assigning the length of the array to a variable won't work.
Try using _set() for the purpose. Other alternatives are directly using the length like:
or use a function that returns the length of the array.
Regards,
Pankaj.
var $len = $arrPicks.length;
for (var $j = 0; $j < $len; $j++) {
var $num = clickCheckboxes($j);
_checkbox("checkedIds[" + $num + "]").click();
}
function clickCheckboxes($j) {
return $arrPicks[$j];
}
and I tried
var $item = 0;
while($arrPicks.length > 0) {
$item = $arrPicks.pop();
_checkbox("checkedIds[" + $item + "]").click();
}
And I tried using $arrPicks.length.
None of them worked.
One point of interest is that I'm seeing a javascript error saying
when I use the FOR loop, like the loop is running into the end of the array instead of paying attention to the loop condition.
Try this code: ensure the array is populated.
Are you facing any issue working with 2011-05-25?
There are made bug fixed in the latest version of Sahi. Please try using it.
Regards
Sumitra