How to wait in protractor till the element is enab

2019-04-06 10:09发布

问题:

Protractor is failing when trying to click a button. Initially the button will be in disabled status (after sometime it will be enabled) and protractor thinks that the button is ready and clicking on the button and failing.

So i want the protractor script to wait till the button is enabled. I have tried below, but it didn't work. Can someone please post the complete code to wait for the element to be enabled?

expect(browser.wait(function(){return browser.driver.isElementPresent(by.id('paynow-info-btn'))}, 10000));

回答1:

There is a very much suitable Expected Condition - elementToBeClickable - it would wait for an element to be both visible and enabled:

var elm = element(by.id('paynow-info-btn'));
var EC = protractor.ExpectedConditions;

browser.wait(EC.elementToBeClickable(elm), 5000);
elm.click();