robot framework - Clear Element Text keyword is not working

十年热恋 提交于 2020-12-03 17:59:08

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/53518481/robot-framework-clear-element-text-keyword-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!