获取元素text的时候,经常会遇到需要去掉(或者替换)获取文本的换行和空格,以对比结果,以下有方法能获取到能输入字符的方法,亲测

这里有使用结果可以参考

方法:
${对比区域} Replace String ${对比区域} \n ${SPACE}
${对比区域} Replace String ${对比区域} ${SPACE} ${EMPTY}
PS:
\n 换行
${EMPTY} 空
${SPACE} 空格
假设说:想把空格替换为换行,如下>

假设说:想把换行替换为空格,如下>

假设说:想把空格替换为空(什么都没有),如下>

解释一下官方的文档

这里的意思是
绿色框内>
假设说原本的变量文本是Hello,word! 然后第三栏填写 word 第四栏 填写 tellus ,得到的结果就是将 Hello,word! 变为 Hello,tellus!
黄色框内>
假设说原本的变量文本是Hello,word! 然后第三栏填写 l 第四栏 填写${EMPTY} 第五栏填写数量等于1,意思是将 l 这个字母替换为空,并且只填换数量一个 l ,得到的结果就是将 Hello,word! 为 Helo,word!
官方说明:
Replaces search_for in the given string with replace_with.
search_for is used as a literal string. See Replace String Using Regexp if more powerful pattern matching is needed. If you need to just remove a string see Remove String.
If the optional argument count is given, only that many occurrences from left are replaced. Negative count means that all occurrences are replaced (default behaviour) and zero means that nothing is done.
A modified version of the string is returned and the original string is not altered.
${str} = Replace String Hello, world! world tellus
Should Be Equal ${str} Hello, tellus!
${str} = Replace String Hello, world! l ${EMPTY} count=1
Should Be Equal ${str} Helo, world!
有什么疑问可以私聊讨论
文章介绍了在处理文本时如何使用特定方法替换字符串中的换行符和空格,例如用ReplaceString函数进行替换,并提供了示例,如将空格替换为换行或空。文中还提到了官方文档对替换功能的解释,包括可选的替换次数参数。
9444

被折叠的 条评论
为什么被折叠?



