I want to make sure the getText returns a non-empty string before continuing the program flow.

I have tried :

var EC = protractor.ExpectedConditions;
await browser.wait(EC.not(EC.textToBePresentInElement($('#result'), '')), 5000);

my div looks similar to:

<div id="result">5</div>

But the browser.wait always passes as the empty character is considered to be included in every string:

console.log('teststring'.includes('')) //always returns true

Could someone let me know the correct way to wait till the text is present in an element? I cannot wait for a specific text as the text changes according to inputs.

2 Answers 2


I went through the source code of the expected condition,

Thee browser.wait expects a promise that resolves to a condition, so i created a promise that resolves to true of getText()==='', else false:

So the solution is :

let textNotToBePresentInElement= function (elem,text)  {

    return async()=> {
    let textreceived=await elem.getText();
    let bool=textreceived === text;
    return !(bool);

 await browser.wait(textNotToBePresentInElement(resultElement,''), 5000, "Result is empty even afer 3 sec");

What worked for me:

async waitForElementTogetText() {
  await browser.waitForAngularEnabled(false);
  *your code here*
  await browser.waitForAngularEnabled(true);
  • 5
    Can you also explain why thi code works? Your post would be much more helpful to others.
    – pavelsaman
    Jan 28, 2020 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.