Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute JavaScript in Robot Framework

Below is my code. When I run this, it shows a WebDriverException. How do I execute JavaScript code in Robot Framework?

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
like image 796
Adnan Ghaffar Avatar asked Oct 30 '25 08:10

Adnan Ghaffar


1 Answers

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

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

So

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

Assuming there is some library (jQuery most probably) that actually understands the $ shorthand.

like image 200
Harri Avatar answered Oct 31 '25 20:10

Harri