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