开发者

Selenium Exception : "return not in a function"

开发者 https://www.devze.com 2023-02-24 22:40 出处:网络
I am writing Selenium开发者_开发技巧 test scripts in C#.Net and I keep bumping into this exception -

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


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);"
);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号