I have a span element on my page. I was wondering how I could extract the text in between the span opening tag and span closing tag. I'm using selenium with protractor in javascript.
<span....>
Inner text
</span>
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With