Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor:How to remove extra space from string just like we use in java getText.trim()

How to remove extra space from string just like we use in java getText.trim() in Protractor,
I used like this:

var columnvalue=rows.get(9).getText();
var columnvalue1=columnvalue.trim();

but i got error: Object [object Object] has no method 'trim'

like image 743
Sujata Dwivedi Avatar asked Feb 18 '15 04:02

Sujata Dwivedi


2 Answers

Andreas' solution is basically correct. I'm just appending some additional info.

I'm not sure what you're using the trim for, but

1) if you're trying to put it into an assertion:

expect(rows.get(9).getText()).toMatch('\s*STRING_TO_MATCH\s*')

or simply

expect(rows.get(9).getText()).toContain('STRING_TO_MATCH')

2) If you want a promise that returns the trimmed value

var columnvalue=rows.get(9).getText();
var columnvalue1=columnvalue.then(function(text) {return text.trim();})
like image 55
hankduan Avatar answered Sep 21 '22 18:09

hankduan


The getText() method returns a Promise object. You need to do like this to get the string:

rows.get(9).getText().then(function(text) {
  console.log(text.trim());
});

If you look at the error you got you will see that it's trying to access the method trim() of an object, not a string.

like image 21
Andreas Argelius Avatar answered Sep 19 '22 18:09

Andreas Argelius