0

I have a java script function to do natural sorting.

But i have no idea how to call this java script and get returned value of js in HP UFT using VB Script.

function alphanum(a, b) {
  function chunkify(t) {
    var tz = [], x = 0, y = -1, n = 0, i, j;

    while (i = (j = t.charAt(x++)).charCodeAt(0)) {
      var m = (i == 46 || (i >=48 && i <= 57));
      if (m !== n) {
        tz[++y] = "";
        n = m;
      }
      tz[y] += j;
    }
    return tz;
  }

  var aa = chunkify(a);
  var bb = chunkify(b);

  for (x = 0; aa[x] && bb[x]; x++) {
    if (aa[x] !== bb[x]) {
      var c = Number(aa[x]), d = Number(bb[x]);
      if (c == aa[x] && d == bb[x]) {
        return c - d;
      } else return (aa[x] > bb[x]) ? 1 : -1;
    }
  }
  return aa.length - bb.length;
}

Please let me know how to call js?

1 Answer 1

2

I built a function to call when I need to have UFT execute some javascript; here it is:

Public Function MISC_ExecuteJavascript(byVal oPage, byVal sJavaScript)
   Dim JSEntry
    Set JSEntry = oPage.object.documentelement.parentnode.parentwindow          
    On Error Resume Next        
    MISC_ExecuteJavascript = JSEntry.eval(sJavaScript)      
    On Error Goto 0
End Function

You pass it the Browser().Page() object that you need the javascript executed on, and the actual javascript call you want executed. The function will then execute it against the page. Hope that helps you out

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.