机器人框架文本字段清除和输入

时间:2016-07-12 20:01:21

标签: input automation textfield robotframework selenium2library

我使用Robot Framework自动化网页。该页面包含不常见的文本字段,如果针对无效值命中 Enter ,则会接收自动输入(不是占位符值)。

这是文本字段:



<div class="bound_value">
	<input id="ember475" size="5" type="text" class="ember-view ember-text-field">
	<input id="ember476" type="checkbox" class="ember-view ember-checkbox">
</div>
&#13;
&#13;
&#13;

我尝试使用输入文字以及按键进行处理。 我是初学者 - 程序员,所以请原谅我的措辞。

  • 使用输入文字:行为就好像我点击了字段一样, 清除内容,按Enter键然后输入值。

  • 使用按键,行为就像我点击字段添加一样 只需键入输入添加到我已经包含的内容。

清除元素文字 + 按键的工作方式与输入文字相同。

我需要一种方法来点击文字字段,删除内容,不按回车,输入文字,然后点击回车。

如何使用RIDE自定义库执行此操作?

提前感谢您的努力。

2 个答案:

答案 0 :(得分:1)

您是否尝试过使用关键字清除元素文字

 Clear Element Text  xpath=//input[@id='ember475']

此处提供更多信息http://robotframework.org/Selenium2Library/doc/Selenium2Library.html#Clear%20Element%20Text

答案 1 :(得分:1)

这可能对您有用:

*** Keywords ***
Clear Field Of Characters
    [Arguments]    ${field}    ${character count}
    [Documentation]    This keyword pushes the delete key (ascii: \8) a specified number of times in a specified field.
    :FOR    ${index}    IN RANGE    ${character count}
    \    Press Key    ${field}    \\8

Input Into Text Field
    [Arguments]    ${field}    ${text}
    [Documentation]    Keyword is just an input text keyword. That clears the text field dynamically.
    ${field text}=    Get Value    ${field}
    ${field text length}=    Get Length    ${field text}
    Clear Field of Characters    ${field}    ${field text length}
    Press Key    ${field}    ${text}

输入所有文本后,不执行此操作的部分将在字段中输入。你可以将下面的内容附加到最后,或者在之后的单独电话中完成。

Press Key    ${field}    \\13    #I believe 13 is the ascii for carriage return, \n may work as well.
相关问题