当尝试按照文档中的说明注册错误处理程序时,出现错误:
Register an event listener to be notified whenever there is an unhandled error.
webdriver.promise.Application. getInstance(). on('uncaughtException', function(e) { console.error('There was an uncaught exception: ' + e.message); });
TypeError: Cannot call method 'getInstance' of undefined
注册错误处理程序的正确方法是什么?
最佳答案
在搜索 WebDriverJS 源代码时我发现了这个:
webdriver.promise.Application = {};
webdriver.promise.Application.getInstance = function() {
webdriver.promise.logDeprecation_(
'webdriver.promise.Application#getInstance()',
'webdriver.promise.controlFlow()');
return webdriver.promise.controlFlow();
};
显然正确的方法是使用:
webdriver.promise.controlFlow().on('uncaughtException', function(e) {
console.error('There was an unhandled exception! ' + e);
});
我已经测试过了,它有效。
(显然我使用的 selenium-webdriver 版本不包含此弃用警告,而只是失败了。)
更新:
webdriver.promise.logDeprecation_ = function(oldSig, newSig) {
if (window.console) {
window.console.log(
'Using deprecated ' + oldSig + ', use ' + newSig +
'instead. This will stop working in Selenium 2.31');
} };
我使用的是 Selenium 2.32。
关于javascript - 如何在 Node 中注册 WebDriverJS 的错误处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21126590/