3
votes

I am automating a web page using Robot Framework. The page has unusual text fields that receive automatic input (not placeholder values) in case Enter is hit for invalid values.

Here is the text field:

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

I have tried handling with Input Text as well as Press Key. I am a beginner-programmer rather, so please forgive me my wording further on.

  • With Input Text: the behavior was as if I clicked on the field, cleared the content, hit Enter and then inputted the value.

  • With Press Key the behavior was as if I clicked on the field add just typed in input adding to what I was already contained.

Clear Element Text+Press Key worked the same way as Input Text.

I need a way to click on the text field, to remove the content, to not hit enter, to type in text, then hit enter.

How can I do this using RIDE Custom Libraries?

Thank you in advance for your effort.

2

2 Answers

6
votes

Have you tried with the keyword Clear Element Text :

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

More information here http://robotframework.org/Selenium2Library/doc/Selenium2Library.html#Clear%20Element%20Text

1
votes

This might work for you:

*** 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}

The part that this doesn't do would be hitting enter in the field once all text is entered. You could attach the below to the end or have it done in a separate call afterwards.

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