请问我做错了什么,导致出现了这个异常:
失败:未知错误:'name'必须是一个字符串 (会话信息:chrome=53.0.2785.101) (驱动程序信息: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),平台=Linux 3.13.0-100-generic x86_64)
function ensureNumberOfTabs(numberOfTabs) {
return this.browser.getAllWindowHandles()
.then(function(handles) {
return handles && handles.length >= numberOfTabs && handles[numberOfTabs];
});
}
this.openTab = function(index, timeout) {
timeout = timeout || DEFAULT_WAIT_FOR_TIMEOUT;
var thisBrowser = this.browser;
var deferred = protractor.promise.defer();
function errHandler(err) {
deferred.reject(err);
}
//wait to open the tab
thisBrowser.wait(ensureNumberOfTabs(index), timeout, 'waiting for opening tab #' + index);
//switch to the tab
thisBrowser.getAllWindowHandles().then(function(tabs) {
var tab = tabs[index]; // this is your new window
thisBrowser.switchTo().window(tab).then(function() {
deferred.fulfill();
}, errHandler);
}, errHandler);
return deferred.promise;
};
据我所知,我实际上是通过 && handles[numberOfTabs]
检查名称是否存在。
当然,问题有时会发生...
任何建议都将非常受欢迎:)
此问题出现在Node 6、Protractor 4.0.11、Chrome 53和Driver 2.25上,适用于Ubuntu 14。
tab
在thisBrowser.switchTo().window(tab)
中是一个字符串吗?看起来这可能是问题所在?堆栈跟踪告诉你错误发生的位置吗? - tehbeardedonetab
的代码的所有者。所以我的问题是为什么我没有得到处理程序? - Andrej