Forum Discussion

akalogeropoulos's avatar
akalogeropoulos
Occasional Contributor
8 years ago
Solved

Passing an array as function parameters from KeyWordTest?

Hi all, I created a function to find a single object on vue from a webpage. If i call the function from script ex: "tblObject = findObject(["ObjectType","innerHTML"],["Table","*ckColumn*"],null);", ...
  • tristaanogre's avatar
    tristaanogre
    8 years ago

    As far as I can tell, there's not a really easy way to pass an array in as a parameter to a script routine via a keyword test.  So, what I did is do a little detection within the function itself to determine if the parameter being passed is a string or if it is an array.  If it is a string, then use the eval function to convert to an array.  If it is not a string, I'm assuming it is an array.  Your function code would look something like this:

    function findObject(mType,mFieldName,mObject)
    {
      var myObject;
      var depth = 10;
       
        Sys.Refresh();
        if (typeof mType == 'string') {
            mType = eval(mType);
        }
        if (typeof mFieldName == 'string') {
            mFieldName = eval(mFieldName);
        }
        
        if(mObject == null)
        {
          mObject = Sys.Browser("iexplore").Page(getURL());
          depth = 20;
        }
            
        myObject = mObject.Find(mType,mFieldName,depth,false);
             
        if(myObject.Exists == true)
        {
            return myObject;
        }
        else
        {
          Log.Message("The object with the " + myFieldName + " parameters was not found");
          return null;
        }
      CollectGarbage();   
    }