gpt4 book ai didi

c# - Selenium 异常 : "return not in a function"

转载 作者:行者123 更新时间:2023-11-29 15:03:59 25 4
gpt4 key购买 nike

我正在用 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 函数获取返回值的最佳方法是什么?

谢谢,

萨尔萨克

最佳答案

来自selenium documentation对于 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.

因此,您只需要取消return:

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

关于c# - Selenium 异常 : "return not in a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5658540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com