Protractor: If Statement if element contains certain text

Viewed 6584

This seems fairly simple but I can't get this to run. I basically want to check if 'div class = balances' contains the text 'EUR' and if it does, I want to do other checks. It works when I use an expect statement: expect(element(by.css('balances')).getText()).toContain('EUR'); This will pass But if I change it to:

if (element(by.css('balances')).getText()).toContain('EUR') {
  console.log('true')
}

I get an error message: .toContain is not defined

What can I use here instead of .toContain? Thanks

Update, I've tried but still no joy:

var bal =element(by.css('balances')).getText().then(function(text){
        if(text.contains('EUR')){
            //do something
        }
       else{
          //do something else
       }
});

1 Answers
Related