Ksenia Starodubtseva
Ksenia Starodubtseva

Reputation: 83

Robot Framework Text Field Clearing and Inputting

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.

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.

Upvotes: 4

Views: 51245

Answers (4)

Sjakiepp
Sjakiepp

Reputation: 83

For those that do not use the Selenium library:

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

Browser library

Upvotes: 1

Sharvik Patel
Sharvik Patel

Reputation: 31

For clearing a paragraph or a sentence or Multiple lines

*** Test Cases ***    
Press Keys   locate_here   CTRL+a   BACKSPACE

Upvotes: 0

J Wipf
J Wipf

Reputation: 11

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.

Upvotes: 1

Said026
Said026

Reputation: 91

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

Upvotes: 8

Related Questions