moshi
moshi

Reputation: 294

protractor getText() returns empty result

I have some list that gets filled with rows by ajax call, above it I have an itemCount span - to show how many rows we have. After the table is filled by rows, the itemCount span value is updated. what I try to do is to copy this itemCount value, to add a new item to the list and then to test that the new itemCount value is bigger by 1 than the old one. The problem, I think, is that when I take the first value from the itemCount span, it is still empty. I tried to add browser.waitForAngular();, etc, but the value is still empty:

element(by.id('itemsCount')).getText().then(function(text) {
    console.log('**********' + text);
});

what I see is just: '**********'

Thanks for any help !

Upvotes: 1

Views: 969

Answers (2)

BarretV
BarretV

Reputation: 1197

you could try using the expected conditions like this.

var itemsCount    = element(by.id('itemsCount'));
var blank         = EC.textToBePresentInElementValue(itemsCount, '');
var itemsNotEmpty = EC.not(blank);

browser.wait(itemsNotEmpty, 5000, "✗ Failed to wait for the item count load").then(function() {
    itemsCount.getText().then(function(text) {
        console.log('**********' + text);
    });
});

Basically wait till the itemsCount isn't blank anymore then get it's text.

Upvotes: 1

user2020347
user2020347

Reputation: 883

There is some different between getText() and getAttribute(), depending on what sort of field it is. Can you try getAttribute and see if it grabs the text?

Upvotes: 0

Related Questions