javascript - 如何在 Node 中注册 WebDriverJS 的错误处理程序?

标签 javascript node.js selenium-webdriver

当尝试按照文档中的说明注册错误处理程序时,出现错误:

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 源代码时我发现了这个:

https://code.google.com/p/selenium/source/browse/javascript/webdriver/promise.js?r=9d98523583afb01a9c5af7125770081d2a3a2210

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/

相关文章:

java - 如何使用 Selenium RemoteWebDriver 删除下载的文件?

javascript - Node.js 与异步 waterfall 模块同步调用

javascript - js/nodejs 使用 request.on() 和 querystring.parse() 的 POST 方法的基本初学者服务器

javascript - 在基础数据上使用原型(prototype)

iphone - 为什么 Objective-C 将 JSON 值转换为 ASCII 字符代码的散列?

node.js - 捕获除/graphql之外的所有路由

java - 在 selenium webdriver 中,如何将控件切换到具有完整形式的 div 元素

java - 如何解析 java.net.SocketPermission

javascript - 如何在提交时从 React-Bootstrap 表单中获取值?

javascript - 当句子中出现某个单词时替换整个字符串 javascript/Google Chrome 扩展