Reputation: 18905
Is it possible to wait on a ExpectedConditions.visibilityOf
without getting a failure if the element has not become visible? I want to handle a situation, where a button might has become visible through an animation and click it away.
browser.wait(conditions.visibilityOf(button), 500).then(function (visible) {
if (visible) {
return button.click().then(function () {/*...*/});
}
});
Upvotes: 1
Views: 1922
Reputation: 18905
I found out, that I can handle the rejected promise returned by wait
to suppress the timeout error:
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
}
});
Upvotes: 11