'robot framework - Clear Element Text keyword is not working

We have a text field with the html structure as below.

<input class="css-1npmunl" name="some.name" aria-label="New Employee ID" data-qa="some.data" placeholder="" value="TEST1" type="Text">

The inbuilt Selenium2Library keyword Clear Element Text ${Field_Locator} doesn't clear the text field as expected. In fact, the field gets cleared for a moment and when I do some other operation after that, like clicking a Save button, the field value is re-populated again with the same value (TEST1) (value attribute contains the actual value of the field).

But when we do the same operation manually, it works as expected. When i checked the DOM using the developer tools, it seems, the Clear Element Text keyword doesn't actually makes the value of the value attribute to empty. But on doing manually, the value of the value attribute is blanked out.



Solution 1:[1]

Since the poster has replied that he/she got their code working, but that answer did not help me; here is my answer.

I ran into exactly the same issue; using Clear Element Text did clear the textfield on the screen, but after submitting the form, the validation still failed.

The Input text ${EMPTY} dit not work for me either.

The way I got it working was by putting some new text in, and immediately removing it again, by using
Press Keys [locator] A+BACKSPACE. I read many answers that find the length of the string, and were backspace'ing that many times. But instead I just simply press the 'a' on the keyboard, and then remove that 'a' again using the backspace.

Solution 2:[2]

It seems like some frameworks will have trouble clearing some text fields. In these cases, I would create a keyword similar to this:

Clear Text Field

  [Arguments]  ${inputField}
  press keys  ${inputField}  CTRL+a+BACKSPACE

Solution 3:[3]

You can try like this

Press Keys ${element} CTRL+A+DELETE

It worked with me, i hope it can help you too

Solution 4:[4]

You can use For loop to solve this problem. Like this

 FOR  ${_}  IN RANGE    0  9 
    Press Keys        ${locator}      BACKSPACE
 END

Solution 5:[5]

There are many ways to do it other than using "Clear Element Text" keyword. I would suggest to use "Press Keys" keyword to select all text in the text field. Then, erase it by pressing "BACKSPACE" key.

Sample RF script as follows:

Press Keys          [locator]               CTRL+a
Press Keys          [locator]               BACKSPACE
Input Text          [locator]               ${new_text}
Click Button        ${save_button}

Solution 6:[6]

One more workaround :

press key ${web_text_email_id} \\1

press key ${web_text_email_id} \\127

input text ${web_text_email_id} ${user_name}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Seadrill
Solution 2 Michael Diaz
Solution 3 Kauã
Solution 4
Solution 5 Nishantha Thilakawardana
Solution 6 Prem Singh Bisht