Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait in protractor till the element is enabled

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));
like image 491
prav kum Avatar asked Jul 03 '16 15:07

prav kum


People also ask

How do you wait for an element in a protractor?

wait(function () { return elem. isDisplayed(); });

What is implicit wait in protractor?

The reason to add implicitlyWait() there is because implicit wait is the default time that protractor waits before passing or throwing an error for an action.

How do you know if a protractor field is disabled?

getAttribute('disabled')). toEqual('disabled'); to accurately verify if something is enabled/disabled.

What is expected conditions in protractor?

ExpectedConditions View code Represents a library of canned expected conditions that are useful for protractor, especially when dealing with non-angular apps. Each condition returns a function that evaluates to a promise. You may mix multiple conditions using and , or , and/or not .


1 Answers

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();
like image 93
alecxe Avatar answered Oct 07 '22 01:10

alecxe