[英]Getting : AttributeError: 'str' object has no attribute 'input_text' on Robot Framework new Keyword
[英]Robot Framework - Input Text with linebreaks
我現在正在測試一些文本編輯器功能,我需要使用換行符在文本字段中輸入文本,而且我不知道如何模擬這種行為。
我正在尋找的是這樣的:
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
感謝您的任何想法。
在需要換行的地方,使用Selenium2Library
中的Press Key
關鍵字作為以下內容,然后可以繼續輸入。
Press Key
$ {Textarea} \\ 13`
這似乎對我有用
*** 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
您可能對Python textwrap模塊很感興趣 :
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中使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.