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

南笙酒味 提交于 2019-12-22 05:09:27

问题


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'


回答1:


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();})



回答2:


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.



来源:https://stackoverflow.com/questions/28576288/protractorhow-to-remove-extra-space-from-string-just-like-we-use-in-java-gettex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!