Is there a way to provide arguments to “Execute JavaScript” in Robot Framework?

♀尐吖头ヾ 提交于 2019-12-08 12:13:53

问题


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;  |

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


回答1:


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');

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.



来源:https://stackoverflow.com/questions/21256845/is-there-a-way-to-provide-arguments-to-execute-javascript-in-robot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!