Protractor. Checking the presence of an input field.

I am writing a simple protractor test that is designed to check if a particular input tag contains text after clicking a button. I have tried several things and am currently trying to use protractor.ExpectedConditions to check if it contains any text. Here is my code:

it("should click submit", function() { var EC = protractor.ExpectedConditions; var status = element(by.id('status')); $("#btnSubmitQuery").click(); var condition = EC.textToBePresentInElement(status, 'C'); browser.wait(condition, 8000, "Text is still not present"); status.getText().then(function (text) { console.log(text); }); }); 

A REST call is made on the server after pressing btnSubmitQuery, but the problem is that I can never get any value for the status. What happens when I run this code is that the browser just waits 8 seconds and then closes, although I can see the text in the element. Nothing is written to the console. Any ideas?

EDIT: The html element I am checking looks like this:

 <td><input id="status" type="text" class="form-control" placeholder="PaxStatus ..." value="{{paxInformation.status}}"ng-readonly="true"></td> 
+4
source share
2 answers

Is not it?

 condition = function () { return status.getAttribute('value').then(function (value) { return value.length > 0 }) }; browser.wait(condition, 8000, "Text is still not present").then(function () { status.getAttribute('value').then(function (text) { console.log(text); }) }); 
+5
source

Just to improve @maurycy's answer. In this particular case, there is a built-in expected condition :

 var EC = protractor.ExpectedConditions; browser.wait(EC.textToBePresentInElementValue(status, 'C'), 5000) 
+7
source

All Articles