我们使用 Selenium 和 django-selenium (SeleniumTestCase) 的 Python 绑定来进行 Selenium 测试。在我们测试的页面上,有几秒钟延迟后创建的 HTML 元素。所以我们想等他们再继续测试。等待本身有效,但等待调用后的每个命令都失败:
class SomeTestCase(SeleniumTestCase):
def test_something(self):
... (some testing code that works)
self.driver.wait_element_present('span.available') # this works
self.driver.wait_element_present('span.connected') # this works, too
self.driver.find_element_by_css_selector('body') # this fails
我通过 selenium 代码进行了调试,发现“find_element_by_css_selector”在内部向 selenium 服务器发布了一个 HTTP 请求(就像每个“检查 xxx 是否存在”命令一样):
http://127.0.0.1:42735/hub/session/<session-id>/element
但此请求返回状态码 500 和此响应文本:
{
"status": 13,
"value": {
"message": "JSON.parse: unexpected non-digit",
"stackTrace": [
{
"methodName": "Dispatcher.executeAs/<",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/driver_component.js",
"lineNumber": 7354
},
{
"methodName": "Resource.prototype.handle",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/driver_component.js",
"lineNumber": 7516
},
{
"methodName": "Dispatcher.prototype.dispatch",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/driver_component.js",
"lineNumber": 7463
},
{
"methodName": "WebDriverServer/<.handle",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/driver_component.js",
"lineNumber": 10152
},
{
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/httpd.js",
"lineNumber": 1935
},
{
"methodName": "ServerHandler.prototype.handleResponse",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/httpd.js",
"lineNumber": 2261
},
{
"methodName": "Connection.prototype.process",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/httpd.js",
"lineNumber": 1168
},
{
"methodName": "RequestReader.prototype._handleResponse",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/httpd.js",
"lineNumber": 1616
},
{
"methodName": "RequestReader.prototype._processBody",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/httpd.js",
"lineNumber": 1464
},
{
"methodName": "RequestReader.prototype.onInputStreamReady",
"fileName": "file:///tmp/tmpnUT34U/extensions/fxdriver@googlecode.com/components/httpd.js",
"lineNumber": 1333
}
]
}
}
结果,整个测试运行阻塞并在默认超时后中止。根据https://code.google.com/p/selenium/wiki/JsonWireProtocol,状态 13 表示“UnknownError”,这并没有让事情更清楚;-)
有没有人也发现了这个?有没有办法解决这个问题?我真的不知道确切的原因可能是什么,我们的页面结构是干净的 html 代码。感谢您的任何建议!