我的代码:
this.condition = function() {
element(by.partialLinkText('Times Jobs')).isDisplayed().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
console.log('Times source not found')
}
});
}如果页面中没有显示"Times“,那么它应该显示Times语句中的任何文本。我怎么能这么做?
我不想使测试失败,只是我需要打印在控制台中的文本。
发布于 2016-05-12 07:38:38
您可以尝试如下:
this.condition = function() {
element(by.partialLinkText('Times Jobs')).isPresent().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
console.log('Times source not found')
}
});
}好像元素没有出现在页面上,而不是给元素找不到错误。
发布于 2016-05-12 07:49:56
您可以使用isPresent(),就像在this answer中一样,但是如果要继续使用isDisplayed(),则必须处理在返回的承诺的错误回调中找不到元素的情况:
element(by.partialLinkText('Times Jobs')).isDisplayed().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
console.log('Times source in page but not displayed');
}
}, function() {
console.log('Times source not in page');
});或者,如果您想输出相同的消息在这两种情况下不在页面,或在页面中,但没有显示,您可以.
element(by.partialLinkText('Times Jobs')).isDisplayed().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
return protractor.promise.rejected();
}
}).catch(function() {
console.log('Times source not in page or in page and not displayed');
});https://stackoverflow.com/questions/37178722
复制相似问题