我正在使用带有Selenium 2的Robotframework &尝试在Firefox上执行Javascript。我尝试了很多不同的语句,例如:
Execute Javascript (function(){alert('hello'); return {'test':'hello'};})()但它们都失败了,都有相同的例外。我只对Firefox (22 & 23)有点问题,但Chrome很好。这是我在运行pybot时在log.html中看到的内容--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)如果我进入webdriver.py并注释掉这行
self.error_handler.check_response(response)然后测试通过了,但我仍然没有真正让javascript执行。
另一个更新-我发现这个问题只影响Firefox22和23。如果我回到Firefox 21,它就可以正常工作了。
发布于 2015-01-16 22:36:31
当我尝试的时候:
Execute Javascript (function(){alert('hello'); return {'test':'hello'};})()我在Firefox 35中看到了警报弹出窗口
https://stackoverflow.com/questions/18191694
复制相似问题