有没有办法为“执行 JavaScript"提供参数?在机器人框架中? [英] Is there a way to provide arguments to "Execute JavaScript" in Robot Framework?

查看:44
本文介绍了有没有办法为“执行 JavaScript"提供参数?在机器人框架中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行以下应采用参数列表的评估函数

I need to execute the following evaluate function which should take an argumentlist

|@{argList}= | arg1 | arg2 | arg3 |

| Execute JavaScript | var header=document.evaluate('//span[contains(text(),"Manage VLAN Profiles")]/following::table[contains(@class,"x-grid")]/tbody/descendant::tr/descendant::td/descendant::*[contains(text(),"AccessVLAN")]',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
return header.textContent;  |

这里我需要将 @{argList} 传递给 JavaScript 函数.

Here I need to pass the @{argList} to the JavaScript function.

推荐答案

如果您的变量是简单类型,您可以将它们嵌入到脚本中,Robot Framework 会在实际调用执行 JavaScript 之前扩展它们.

If your variables are simple types you can just embed them in the script and Robot Framework will expand them before actually invoking Execute JavaScript.

${argList}=    Create List    Sally    45
Execute JavaScript    alert('Hello ${argList[0]}, you are ${argList[1]} years old');

如果上述方法对您不起作用,并且您希望能够直接传递参数,则可以通过访问 WebDriver 实例.您可以引用通过名为 arguments 的数组传递的参数.

If the above does not work for you and you want to be able to pass arguments directly, you can by accessing the WebDriver instance. You can reference the arguments passed via the array called arguments.

${argList}=    Create List    Sally    45
${s2l}=    Get Library Instance    Selenium2Library
Call Method    ${s2l._current_browser()}    execute_script    alert('Hello ' + arguments[0] + ', you are ' + arguments[1] + ' years old');    @{argList}

如果您想要此功能,您应该在问题跟踪器上请求它.请注意,执行此操作时,失败机制将不起作用.

If you want this functionality you should request it on the issue tracker. Note the on failure mechanism will not work when doing this.

这篇关于有没有办法为“执行 JavaScript"提供参数?在机器人框架中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆