Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having an issue using substring in protractor

Tags:

protractor

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.

like image 605
user2040060 Avatar asked Nov 28 '25 05:11

user2040060


1 Answers

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);
});
like image 183
Leo Gallucci Avatar answered Nov 29 '25 22:11

Leo Gallucci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!