【问题标题】:Selenium Exception : "return not in a function"Selenium 异常:“不在函数中返回”
【发布时间】:2011-08-05 05:42:42
【问题描述】:

我正在用 C#.Net 编写 Selenium 测试脚本,但一直遇到这个异常 -

ERROR: Threw an exception: return not in function

这是我抛出错误的代码行 -

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

谁能建议为什么会出现异常以及从 GetValue javascript 函数获取返回值的最佳方法是什么?

谢谢,

萨尔塔克

【问题讨论】:

    标签: c# javascript exception selenium


    【解决方案1】:

    selenium documentationGetEval

    获取评估结果 指定的 JavaScript sn-p。这 sn-p 可能有多行,但是 只有最后一行的结果 被退回。

    因此你只需要去掉return

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

    【讨论】:

    • 收到此错误 - 错误:引发异常:win.editAreaLoader.GetValue 不是函数
    • 它是一个开源 api。当我没有返回任何值时,GetEval 工作正常。
    • @saarthak - 听起来GetValueundefined。你确定不是getValue
    • 它是 getValue 而不是 GetValue。我多么愚蠢!感谢您指出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    相关资源
    最近更新 更多