0

我现在正在测试一些文本编辑器功能,我需要用换行符将文本输入到文本字段中,我不知道如何模拟这种行为。机器人框架 - 带换行符的输入文本

我正在寻找的是这样的:

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 

感谢您的任何想法。

+0

这似乎不是一个'selenium' /'硒webdriver'相关的问题,如纯'蟒蛇+ selenium'这个工作原理就像'.send_keys(“第一行\ n第二行”)'...... – Andersson

+0

尝试'按下按键'按回车,你可以继续输入? –

回答

-1

你可以在Python textwrap module被insterested:

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的解决方案,它可能不是robotframework,我不知道使用。

+0

它的工作方式就像是将字符串与断线分开,对吗? –

+0

@PetrBečka我编辑了答案来添加详细信息 – Tryph

1

使用Press Key关键字从Selenium2Library如下,你想要一个新的行,那么你可以继续打字。

Press Key $ {textarea的} \ 13`

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 
+0

而你如何定位输入字段来放置文本? –

+0

这里我只是举个例子。 – Vivi

+0

这里id = oldText是你要输入文本的$ {locator}。你可以通过检查网页来获取定位器。我会建议Firepath或者Firebug(对于mozilla)。 – Vivi