机器人框架 - 输入带有换行符的文本

时间:2016-11-04 10:27:50

标签: python selenium selenium-webdriver automated-tests robotframework

我现在正在测试一些文本编辑器功能,我需要使用换行符在文本字段中输入文本,我不知道如何模拟这种行为。

我正在寻找的是:

Input Text  ${locator}  "text with linebreak \n"

或者如何将输入文本分成多行?
如果我想要而不是这个:

Input Text  ${locator}  Such a long text to input that cannot even fit on my computer's monitor size

执行此操作,将此输入文本拆分为更多行:

Input Text  ${locator}  Such a long text to input that cannot + 
                        + even fit on my computer's monitor size

感谢任何想法。

3 个答案:

答案 0 :(得分:1)

使用Press Key中的Selenium2Library关键字作为您想要新行的地方,然后您可以继续输入。

Press Key $ {Textarea} \ 13`

答案 1 :(得分:0)

这似乎对我有用

*** Test Cases ***
SomeRandom
    Open Browser            http://www.textfixer.com/tools/remove-line-breaks.php
    Input text              id=oldText    Vivi is trying to enter \n can he do that? \n I think so \n lets try

答案 2 :(得分:-1)

您可能对Python textwrap module感兴趣:

In [1]: import textwrap

In [2]: s = "I am not rambling. " * 10

In [3]: textwrap.wrap(s, 80)
Out[3]:
['I am not rambling. I am not rambling. I am not rambling. I am not rambling. I am',
 'not rambling. I am not rambling. I am not rambling. I am not rambling. I am not',
 'rambling. I am not rambling.']

它巧妙地(在单词之间)分割最多80个字符的字符串列表中的长文本(在此示例中,它是可配置的)。 然后你只需要在每个字符串之间用换行符连接这些字符串:

"\n".join(textwrap.wrap(s, 80))

注意:因为它是一个纯python解决方案,它可能无法在我不知道的机器人框架中使用。

相关问题