根据Selenium IDE HTML 测试中的 JavaScript 函数,这应该是可能的:
<tr>
<td>storeEval</td>
<td>function(input) {return input.replace('foo', 'bar');}</td>
<td>replaceText</td>
</tr>
<tr>
<td>storeEval</td>
<td>replaceText('foo')</td>
<td>var</td>
</tr>
相反,我得到以下异常:
function statement requires a name
给它一个名字后,语句运行:
<tr>
<td>storeEval</td>
<td>function replaceText(input) {return input.replace('foo', 'bar');}</td>
<td>replaceText</td>
</tr>
但是下一行找不到定义:
replaceText is not defined
我也尝试过引用变量而不是函数:
<tr>
<td>storeEval</td>
<td>${replaceText}('foo')</td>
<td>var</td>
</tr>
但显然它仍然未定义:
null is not a function
我还尝试制作一个匿名函数:
<tr>
<td>storeEval</td>
<td>(function (input) {return input.replace('foo', 'bar')})</td>
<td>replaceText</td>
</tr>
并用括号运行它:
<tr>
<td>storeEval</td>
<td>(${replaceText})('foo')</td>
<td>var</td>
</tr>
错误:
missing ) in parenthetical
并且没有:
<tr>
<td>storeEval</td>
<td>${replaceText}('foo')</td>
<td>var</td>
</tr>
错误:
missing ; before statement