Robotframework Selenium2执行Javascript

时间:2013-08-12 16:07:26

标签: selenium-webdriver robotframework

我正在使用Robotframework与Selenium 2&试图在Firefox上执行Javascript。 我尝试了很多不同的陈述,例如:

Execute Javascript    (function(){alert('hello'); return {'test':'hello'};})()

但他们都失败了同样的例外。我只是遇到了Firefox(22& 23)的问题,但Chrome很好。这是我在使用pybot --loglevel debug。

运行时在log.html中看到的内容
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)

如果我进入webdriver.py并注释掉

self.error_handler.check_response(response)

然后测试通过,但我仍然没有实际执行javascript。

另一个更新 - 我发现此问题仅影响Firefox 22&amp; 23.如果我回到Firefox 21那就可以了。

1 个答案:

答案 0 :(得分:0)

当我尝试时:

Execute Javascript    (function(){alert('hello'); return {'test':'hello'};})()

我在Firefox 35中看到了警告弹出窗口