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.
Selected Boxes
Hi (again),
I've got a Select box in my webpage, and I would like to store all the value in an array...
For example there is a selected box :
array[0]= "Cat";
array[1]= "Dog";
...
array[5]= "Turtle";
I've checked in Sahi's APIs and there is a function _getSelected(...) but it works when you know which value ou want to get (and you have to do that manually).
Here, I need a solution that is able to pick up all the option of the selectbox and to store them in the array...I need this because the number of option can change everyday .....
Any idea ?
I've got a Select box in my webpage, and I would like to store all the value in an array...
For example there is a selected box :
<select name="myselectedbox">
<option value="1">Cat</option>
<option value="2">Dog</option>
<option value="3">Bird</option>
<option value="4">Rabbit</option>
<option selected value="5">Cow</option>
<option value="6">Turtle</option>
</select>
I want to store all the values of the options in an array. In fact I would like to have :array[0]= "Cat";
array[1]= "Dog";
...
array[5]= "Turtle";
I've checked in Sahi's APIs and there is a function _getSelected(...) but it works when you know which value ou want to get (and you have to do that manually).
Here, I need a solution that is able to pick up all the option of the selectbox and to store them in the array...I need this because the number of option can change everyday .....
Any idea ?
Comments
Right now I can only give some logic how you can do this. The script below needs to be debugged. Regards,
Pankaj.
I wll test it this morning, thank you for all
I've tried your solution and I've searched a little bit around "select" :
I've found this: So I think that if I type but replacing mySelect by the name of my select box which is "dev_country",
It should at least display the length of my select box ... But SAHI says that dev_country has no properties...
The name of my select box is dev_country" and the name of my form is "simdevice". So I've tried with :
dev_country.options.length
document.simdevice.dev_country.length
form.dev_country.options.length
... in vain
Nothing works !
Does Sahi knows JavaScript after all ?!
In sahi controller try if this thing works.. Regards,
Pankaj.
It works perfectly in sahi controller, by running the button "test", but when I playback the script, sahi fails !!!
_select("dev_country") has no propertie
or
el has no propertie !
My mind is getting twisted...
use _set() to set the array elements. If you do it directly it will throw the same error of element has not\ properties. I suppose it has something to do with page dependant variables.
Regrds,
Pankaj.
Summary :
If I use $arr[$i]=_select("dev_country").options[$i].text; it works in sahi controller but not as a script launched
If I use _setValue : [Exception] TypeError: el has no properties
If I use _set : [Exception] ReferenceError: _set is not defined
Edit : I thought it was because the value of _set(element,value) musn't be in JavaScript so I've done :
$temp = _select("dev_country").options[$i].text;
_setGlobal($arr[$i], $temp);
But it still don't work ...
I've tried with _set() but it does not work on both ...
So I've tried this , and it works :