机器人框架 - 清除元素文本关键字不起作用 [英] robot framework - Clear Element Text keyword is not working

查看:66
本文介绍了机器人框架 - 清除元素文本关键字不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 html 结构的文本字段,如下所示.

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

内置的 Selenium2Library 关键字 Clear Element Text ${Field_Locator} 没有按预期清除文本字段.事实上,该字段会被清除片刻,然后当我执行其他一些操作时,例如单击 Save 按钮,该字段值会再次重新填充相同的值 (TEST1) (value 属性包含字段的实际值).

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

但是当我们手动执行相同的操作时,它会按预期工作.当我使用开发人员工具检查 DOM 时,似乎 Clear Element Text 关键字实际上并未将 value 属性的值设为空.但是在手动执行时,value 属性的值会被清空.

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.

推荐答案

我遇到过几次相同的问题(React 总是在它的最底层!:) 并尝试了不同的方法.按照评论中的建议设置空值有时会起作用,但会随机失败.

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.

最后,我确定了一个直接"解决方案——发送与当前值长度一样多的退格字符.副作用是这也接近正常的用户交互:);真正的副作用是这比 Clear Element Text 调用慢,较长的文本可能需要几秒钟.

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.

以下是如何在 RF 中执行此操作的示例:

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

这篇关于机器人框架 - 清除元素文本关键字不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆