protractor getText() returns empty result

2019-08-10 00:56发布

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 !

2条回答
你好瞎i
2楼-- · 2019-08-10 01:37

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.

查看更多
女痞
3楼-- · 2019-08-10 01:41

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?

查看更多
登录 后发表回答