I am new to protractor and having issues with basic javascript. I want to get the text from an element and only take the the first 5 characters.
When I try to run this statement
var searchDate = element(by.id("tag")).getText().substring(0,5);
I get this error
Message: TypeError: Object [object Object] has no method 'substring'
Not sure what I am doing wrong.
That's because Object [object Object] is a promise.
Do instead:
element(by.id("tag")).getText().then(function(text) {
var searchDate = text.substring(0,5);
});
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