我发现,我可以处理被拒绝的承诺,wait
以抑制超时错误:
browser.wait(conditions.visibilityOf(button), 500).then(function () { // It is visible return button.click().then(function () {/*...*/}); }, function() { // It is not visible if (shouldExpectVisibility) { // If I want to fail, I could reject again return protractor.promise.rejected('No such button'); } else { // If I don't want to fail, I do nothing } });