18 January 2026:


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.

regrding Arrays

arunbalaarunbala Members
edited November -1 in Sahi - Open Source
Hi,
Here is my scenario.
_setSelected(_select("ctl00\$cphClientBody\$ddlISO"), $Currency); //$currency is given by Excel.

am having number of groups like this,

Var $1 = Rupees,dollars
var $2 = dinar,pound
And so on...

After this am using switch case

switch case(var);

case 1: some actions
case 2: Some actions

And so on.....

Logic is First i have to search my string in All the arrays. If an array gets matched then corresponding case has to be executed...

Pls Help...

Comments

  • globalwormingglobalworming Moderators
    edited February 2012
    Hi arunbala

    I don't really get you.. what are the arrays you are talking about? please provide more information on your problem. I hope this can help you http://www.tutorialspoint.com/javascript/array_indexof.htm or
    // will return index of string in array
    function arraySearch($array, $string){
      for ($i=0, $i<$array.length, $i++){
         if($array[$i]== $string){
           return $i;
           break;
         }
      }
    }
    var $a=[dollar,dinar]
    
    switch case($a[arraySearch($a, "dinar")]);
    case 1: some actions
    case 2: Some actions
    
  • Hi arunbala,

    Encapsulate all the available array into a new array. so the new array becomes a two dimensional array and iterate over it to find, if the string exists. If the string exists, get the index of the array and using the index, you can execute certain switch case.

    For eg:
    function arraySearch($string){
        var $a=["a","b","c"];
        var $b=["d","e","f"];
        var $c=["g","h","i"];
        var $d=[$a,$b,$c];
        for(var $i=0;$i<$d.length;$i++){
            for(var $j=0;$j<$d[$i].length;$j++){
                if($d[$i][$j]==$string){
                    return $i;
                    break;
                }
            }
        }
    }
    var $e=arraySearch("i");
    switch($e)
    {
    case 1:
        _alert("1");
        break;
    case 2:
        _alert("2");
        break;
    case 3:
        _alert("3");
        break;
    default:
        _alert("default");
        break;
    }
    

    Hope this might help you.

    Regards,
    Theeran.
  • arunbalaarunbala Members
    edited February 2012
    Hi theeran,
    Its working fine. But in my case For $string am passing the values from Excel. While passing, it wont return the i value. And not going to switch case.

    I got the error like this,
    _setSelected(_select("ctl00\\$cphClientBody\\$ddlISO"), "i"); Error: The parameter passed to _setSelected was not found on the browser

    Please look into that pblm.

    Thnx.
  • arunbalaarunbala Members
    edited February 2012
    Hi,
    Finally i got it... I didnt return the i value to the function... Directly took that value..

    Thnx.. Its wrkn fine..

    My script:
    for(var $i=0;$i<$ConArray.length;$i++){
    for(var $j=0;$j<$ConArray[$i].length;$j++){
    if($ConArray[$i][$j] == $Currency){
    _alert($i);
    switch ($i)
    {
    case 0:
This discussion has been closed.