Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 261
mo-ta-to Avatar asked Jan 01 '23 13:01

mo-ta-to


1 Answers

I've ran into the same issue a couple of times (React is always at the bottom of it! :) and tried different things. Setting an empty value as suggested in the comments sometimes works, but fails at random.

At the end, I've settled at a "direct" solution - sending as many backspace characters as the length of the current value. A side effect is this is also close to a normal user interaction :); the real side effect is this is slower than a Clear Element Text call, can take a couple of seconds for longer text.

Here's a sample how to do it in RF:

${value}=     Get Element Attribute   ${Field_Locator}      value
${backspaces count}=    Get Length      ${value}
Run Keyword If    """${value}""" != ''    # if there's no current value - no need to slow down by an extra SE call
...     Repeat Keyword  ${backspaces count +1}  Press Key  ${Field_Locator}   \\08    # this is the code for the backspace key; "backspaces count +1" - just too be sure :)
like image 75
Todor Minakov Avatar answered Feb 22 '23 22:02

Todor Minakov