1

我正在使用带有 Selenium 2 的 Robotframework 并尝试在 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 和 23。如果我回到 Firefox 21,那么它工作正常。

4

1 回答 1

0

当我尝试时:

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

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

于 2015-01-16T14:36:31.070 回答