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.
Not able to iterate through array with more than 100 elements?
Hello,
I have select with 176 option elements. When I try to iterate through the array with all options the script fails at 100th element with "ERROR TypeError: Cannot read property 'value' from undefined".
I will be really grateful if anyone who have encountered this and managed to solve it share their experience?
I'm using open source Sahi v44_20130429 and Mozilla Firefox 12.0.
Here is my script:
var $options = new Array();
var $length;
$options = _select("myselect").options;
_set($length, $options.length);
//Elements count shown here is correct.
//_alert($length);
//Correct values displayed here as well.
//_alert($options[3].text);
//_alert($options[3].value);
for(var $i = 0; $i < $length; $i++)
{
var $value;
_set($value, $options[$i].value);
if($value == 2601)
{
do_something;
}
}
Regards,
Iskren
I have select with 176 option elements. When I try to iterate through the array with all options the script fails at 100th element with "ERROR TypeError: Cannot read property 'value' from undefined".
I will be really grateful if anyone who have encountered this and managed to solve it share their experience?
I'm using open source Sahi v44_20130429 and Mozilla Firefox 12.0.
Here is my script:
var $options = new Array();
var $length;
$options = _select("myselect").options;
_set($length, $options.length);
//Elements count shown here is correct.
//_alert($length);
//Correct values displayed here as well.
//_alert($options[3].text);
//_alert($options[3].value);
for(var $i = 0; $i < $length; $i++)
{
var $value;
_set($value, $options[$i].value);
if($value == 2601)
{
do_something;
}
}
Regards,
Iskren
Best Answer
-
Hi Iskren,
You will have to do the following steps to get your script working fine.
1) Open the following file:<path_to_your_sahi_folder>/htdocs/spr/lib.js
2) Search for the following string in the file:for (var i=0; i<100; i++)
3) replace the following code (for loop):for (var i=0; i<100; i++){ Stub.prototype.__defineGetter__(""+i, indexBinder(i)); }
with
for (var i=0; i<200; i++){ Stub.prototype.__defineGetter__(""+i, indexBinder(i)); }
Here we replaced 100 with a number greater than the number of options in your select box, lets say 200.
Start Sahi and run your test again.
It should work for you now.
Regards.
This discussion has been closed.
Answers
It works now! Thank you so much!
Regards,
Iskren
I am glad to help. I will be closing this discussion now.
Regards.