Forum Discussion

blatec's avatar
Occasional Contributor
8 years ago

Array Type mismatch in javascript

Hi,   if i call this function csSetControlValue("ctrlInterestRateTypeSleList",['003','004']) in the chrome console (F12) it work correct.   But if i try to call this -> Aliases.browser.MainPage.c...
  • tristaanogre's avatar
    8 years ago

    I think, but I'm not sure, that this is because you are passing a native JavaScript array through to a function that comes from an object in the AUT.  While it works just fine through the chrome console (because you are accessing the JavaScript process directly), going through the TestComplete code, I think, requires that array to be passed, not as a native JavaScript array but as a variant array.

    Try converting your array first using something like:


    function ConvertJScriptArray(JScriptArray)
      // Uses the Dictionary object to convert a JScript array
      var objDict = Sys.OleObject("Scripting.Dictionary");
      for (var i in JScriptArray)
        objDict.Add(i, JScriptArray[i]);
      return objDict.Items();

    Again, I could be wrong, but that seems to be the best bet.

  • tristaanogre's avatar
    8 years ago

    Just a bit of investigation... drop a break point on the var test1 = line and then bring up the evaluator for your test variable.  If you can screenshot that, that would be great.  I want to see how TestComplete sees the item.

    The other thing to try is that, if you're using JavaScript, getting values of indexed items that are not native JavaScript objects requires the use of the $get method.

    So... something else to try is to do the following:

    function test()
    var test = Aliases.browser.MainPage.contentDocument.script.csGetControlValue("ctrlInterestRateTypeSleList");
    Log.Message("Value of item 0 is : " + test.$get('0'));

    Even though the code you are calling is a JavaScript method on the page itself, from the previous problem, it's obvious that TestComplete is putting it through some sort of process that masks it as a JavaScript array.  I've had this problem myself in a slightly different situation so I think the $get method should work.