Transparency: how to remove excess space from a string in the same way as we use getText.trim () in java

How to remove excess space from a string in the same way we use java getText.trim() in java getText.trim() in Protractor ,
I used like this:

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

but I got an error: Object [object Object] does not have a trim method

+6
source share
2 answers

Andreas's decision is basically the right one. I just add more info.

I'm not sure what you use cropping for, but

1) if you are trying to include it in a statement:

 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 need a promise that returns a trimmed value

 var columnvalue=rows.get(9).getText(); var columnvalue1=columnvalue.then(function(text) {return text.trim();}) 
+7
source

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

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

If you look at the error you received, you will see that it is trying to access the trim() method of the object, not the string.

+6
source

Source: https://habr.com/ru/post/982660/


All Articles