I'm using Robotframework with Selenium 2 & trying to Execute Javascript on Firefox. I've tried loads of different statements, for example:
Execute Javascript (function(){alert('hello'); return {'test':'hello'};})()
But they all fail with the same exception. I'm only having a problem with Firefox (22 & 23) but Chrome is fine. This is what I see in the log.html when I run with pybot --loglevel debug.
KEYWORD: Selenium2Library.Execute Javascript (function(){alert('hello'); return {'test':'hello'};})()
Documentation:
Executes the given JavaScript code.
Start / End / Elapsed: 20130812 16:58:35.184 / 20130812 16:58:46.934 / 00:00:11.750
Expand AllKEYWORD: Selenium2Library.Capture Page Screenshot
16:58:35.185 INFO Executing JavaScript:
(function(){alert('hello'); return {'test':'hello'};})()
16:58:35.185 DEBUG POST http://127.0.0.1:54281/hub/session/df0916e9-1bf1-fa42-98c5-c3d7a981c096/execute {"sessionId": "df0916e9-1bf1-fa42-98c5-c3d7a981c096", "args": [], "script": "(function(){alert('hello'); return {'test':'hello'};})()"}
16:58:46.934 FAIL WebDriverException
16:58:46.934 DEBUG Traceback (most recent call last):
File "<string>", line 2, in execute_javascript
File "/Users/will/apps/OMERO.libs/lib/python2.6/site-packages/Selenium2Library/keywords/keywordgroup.py", line 12, in _run_on_failure_decorator
return method(*args, **kwargs)
File "/Users/will/apps/OMERO.libs/lib/python2.6/site-packages/Selenium2Library/keywords/_javascript.py", line 92, in execute_javascript
return self._current_browser().execute_script(js)
File "/Users/will/apps/OMERO.libs/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 397, in execute_script
{'script': script, 'args':converted_args})['value']
File "/Users/will/apps/OMERO.libs/lib/python2.6/site-packages/Selenium2Library/webdrivermonkeypatches.py", line 11, in execute
result = self._base_execute(driver_command, params)
File "/Users/will/apps/OMERO.libs/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "/Users/will/apps/OMERO.libs/lib/python2.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 158, in check_response
raise exception_class(message, screen, stacktrace)
If I go into webdriver.py and comment out the line
self.error_handler.check_response(response)
then the test passes, but I still don't actually get the javascript executing.
Another Update - I found that this issue only affects Firefox 22 & 23. If I go back to Firefox 21 then it works OK.