Johnny Codes
Johnny Codes

Reputation: 41

Calling Javascript in Watin

I am trying to execute some JavaScript using C# eval call.

browser.Frames[1].Eval("myFunctionCall(" + Id + ", 1, " + RowNumber + ");");

It cannot seem to find the function as it throws a 'JavaScriptException' "The value of the property 'myFunctionCall' is null or undefined, not a Function object"

Here is the back story.
I figured out by tracing the JavaScript that this is the function called when element of interest is clicked on. So I bring up the page in the browser and execute this JavaScript. On loading, I get above error.
I am beginner and I am not sure how to call the JavaScript that is referenced remotely.

In summary, I would like to call javascript method. Any ideas?

Thanks!

Upvotes: 4

Views: 2122

Answers (1)

Andres
Andres

Reputation: 95

I would start by making sure that the JavaScript containing that function is actually loaded when using it in WatiN. You could try to declare the function before calling it.

Browser.Eval(
  "function myFunctionCall(Id, Num, RowNumber) {" +
  " var a = 0;" +
  " var b = 0;" +
  "}" + 
  "myFunctionCall(" + Id + ", 1, " + RowNumber + ");");

Hope it helps!

Additionally, make sure that the function is available from your frame. In other words, that the frame has access to that function.

Upvotes: 1

Related Questions