如何在Robot Framework中执行JavaScript

Adn*_*far 3 selenium automated-tests robotframework selenium-webdriver

下面是我的代码。当我运行它时,它显示一个WebDriverException。如何在Robot Framework中执行JavaScript代码?

这段return $(arguments[0]).data('${ToolTip}').options.title代码在-java Selenium Web驱动程序中运行良好。

Mouse Over    ${CreateTask}
    Execute JavaScript    return $(arguments[0]).data('${ToolTip}').options.title
Run Code Online (Sandbox Code Playgroud)

Har*_*rri 5

来自http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Execute%20Javascript

请注意,默认情况下,代码将在Selenium对象本身的上下文中执行,因此将引用Selenium对象。使用window来引用应用程序的窗口,例如window.document.getElementById('foo')。

所以

Mouse Over    ${CreateTask}
    Execute JavaScript    return window.$(arguments[0]).data('${ToolTip}').options.title
Run Code Online (Sandbox Code Playgroud)

假设有一些库(最有可能是jQuery)实际上理解$速记。