Protractor: element.getText() returns an object and not String

Roopali Bansal picture Roopali Bansal · Apr 6, 2015 · Viewed 67.2k times · Source

I have an element defined as

this.clientRowName = element(by.id('CLIENT_NAME')); //page object file

I want to read the text in this element which is "ABC" but doing: var client = page.clientRowName.getText();

returns an object instead of a string. Is there any other way that I can get the text for the element

Answer

alecxe picture alecxe · Apr 6, 2015

getText() returns a promise, you need to resolve it:

page.clientRowName.getText().then(function (text) {
    console.log(text);
});

Or, if you just want to assert the text, let expect() resolve the promise for you:

expect(page.clientRowName.getText()).toEqual("ABC");

Promises and the Control Flow documentation page should clear things up.