WebElement.clear() 对文本框有什么作用? [英] What does WebElement.clear() Do to TextBoxes?

查看:31
本文介绍了WebElement.clear() 对文本框有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在使用 selenium 时遇到了问题,在自定义文本框上调用 clear() 会导致稍后在测试中输入文本时出现问题.文本框会检查 (JavaScript) browserEvents,尤其是 keyDown 事件.我试图弄清楚 clear() 做了什么,看看这是否会影响事情,但我似乎找不到任何细节.

I've recently run into a problem working with selenium where calling clear() on a custom text box causes issues when entering text later in the test. The text box does check for (JavaScript) browserEvents, particularly keyDown events. I tried figuring out what clear() does to see if that could be affecting things, but I can't seem to find any specifics.

Selenium Java 绑定的源代码 表示 clear() 不使用键盘或鼠标模拟 来清除文本框中的文本.那么它到底是做什么的呢?

The source for the Selenium Java bindings shows that clear() does not use keyboard or mouse simulation to clear away the text from the text box. So what does it do, exactly?

推荐答案

clear() 方法执行 "Automation Atom",这是一个 JavaScript 函数,旨在为浏览器提供自动化功能的最小基本单元.在 clear() 的情况下,该函数将元素的 value 属性设置为空字符串 (''),然后触发 onchange 元素上的事件.您感兴趣的原子函数是 bot.action.clear()

The clear() method executes an "Automation Atom", which is a JavaScript function intended to provide the smallest basic unit of automation functionality for a browser. In the case of clear(), that function sets the value property of the element to an empty string (''), then fires the onchange event on the element. The atoms function you're interested in is bot.action.clear()

这篇关于WebElement.clear() 对文本框有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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