3

I am writing Selenium test scripts in C#.Net and I keep bumping into this exception -

ERROR: Threw an exception: return not in function

Here is my line of code which throws the error -

string code = selenium.GetEval(
   "var win = this.browserbot.getUserWindow(); "+
   "return win.editAreaLoader.GetValue(win.loadedCodeEditorID);"
);

Can anyone please suggest why the exception is coming and what could be the best way to get a return value from GetValue javascript function?

Thanks,

Saarthak

1 Answer 1

2

From the selenium documentation for GetEval:

Gets the result of evaluating the specified JavaScript snippet. The snippet may have multiple lines, but only the result of the last line will be returned.

Therefore you simply need to leave off the return:

string code = selenium.GetEval(
   "var win = this.browserbot.getUserWindow(); "+
   "win.editAreaLoader.GetValue(win.loadedCodeEditorID);"
);
Sign up to request clarification or add additional context in comments.

4 Comments

Got this error - ERROR: Threw an exception: win.editAreaLoader.GetValue is not a function
its an open source api. The GetEval works fine when I am not returning any value.
@saarthak - by the sounds of it GetValue is undefined. Are you sure it's not getValue?
it was getValue instead of GetValue. How stupid of me! Thanks for pointing out.

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.