如何在 Robot Framework 中执行 JavaScript [英] How to execute JavaScript in Robot Framework
问题描述
下面是我的代码.当我运行它时,它显示一个 WebDriverException.如何在 Robot Framework 中执行 JavaScript 代码?
Below is my code. When I run this, it shows a WebDriverException. How do I execute JavaScript code in Robot Framework?
这个,return $(arguments[0]).data('${ToolTip}').options.title
代码在 -java Selenium web driver 中运行良好.
This, return $(arguments[0]).data('${ToolTip}').options.title
code is doing well in -java Selenium web driver.
Mouse Over ${CreateTask}
Execute JavaScript return $(arguments[0]).data('${ToolTip}').options.title
推荐答案
请注意,默认情况下,代码将在Selenium 对象本身,因此 this 将引用 Selenium 对象.利用window 引用您的应用程序的窗口,例如window.document.getElementById('foo').
Note that, by default, the code will be executed in the context of the Selenium object itself, so this will refer to the Selenium object. Use window to refer to the window of your application, e.g. window.document.getElementById('foo').
所以
Mouse Over ${CreateTask}
Execute JavaScript return window.$(arguments[0]).data('${ToolTip}').options.title
假设有一些库(最有可能是 jQuery)真正理解 $
简写.
Assuming there is some library (jQuery most probably) that actually understands the $
shorthand.
这篇关于如何在 Robot Framework 中执行 JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!