Extract inner from a span element in selenium/protractor javascript Extract inner from a span element in selenium/protractor javascript selenium selenium

Extract inner from a span element in selenium/protractor javascript


It is actually called a text of an element. Use getText():

var elm = element(by.id("myid"));expect(elm.getText()).toEqual("My Text");

Note that getText() as many other methods in protractor returns a promise. expect() "knows" how to resolve the promise - it would wait until the real text value would be retrieved and only then perform an assertion.

If you want to see an actual text value on the console, resolve the promise with then():

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


To find elements on a web page, Protractor uses locators. Read up on them here: https://github.com/angular/protractor/blob/master/docs/locators.mdSince you haven't posted any code, this may differ from the solution you need. The locator I'll use is by using its ID.

var foo = element(by.id('yourspanID')).getText();