问题描述
我有一个Web应用程序,我正在使用HP的UFT软件进行测试。在我的应用程序中,
有一个带有onkeydown属性的文本字段。当在文本字段中按下某个键时,将调用一个函数,该函数根据按下的键触发不同的操作。我对enter键感兴趣。按下回车键后,将在表单中创建行。如何模拟在场内按下的回车键?
I have a web application that I am testing with HP's UFT software. Within my application,there is a text field with an onkeydown attribute. When a key is pressed within the text field, a function is called which triggers different actions depending on what key was pressed. I am interested in the enter key. When the enter key is pressed, rows are created within the form. How can I simulate the enter key being pressed within the field?
我试过
field1.Set Chr(13)
field1.FireEventonkeydown
但它不会触发事件。
我正在使用SendKeys命令尝试aviod。
I am trying aviod using the SendKeys command.
推荐答案
如果您使用设备重播模式(如)并发送 vbCRLF
您的应用程序将能够看到回车键。
If you use device replay mode (as described in this answer) and send a vbCRLF
your application will be able to see the enter key.
Setting.WebPackage("ReplayType") = 2 ''# Changes to device mode
Browser("Enter").Page("Enter").WebEdit("WebEdit").Set "a" & vbCRLF
这适用于以下样本页面(在IE上):
This works (on IE) for the following sample page:
<!DOCTYPE html>
<html>
<head>
<title>Enter</title>
<script>
function okd() {
if (event.keyCode == 13)
alert("Got enter");
}
</script>
</head>
<body>
<textarea onkeydown="okd()"></textarea>
</body>
这篇关于如何在UFT中模拟键盘输入事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!