How do you simulate a keyboard enter event in UFT

纵然是瞬间 提交于 2019-12-04 15:01:07
Motti

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

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>

These are the some methods i have tried for simulate keyboard events and worked for me..

Set oShell = CreateObject("WScript.Shell")

oShell.SendKeys "{TAB}"           ' Click Tab Key
oShell.SendKeys "{ENTER}"         ' Click Enter\Return

Also i have used

Type micAltDwn + "RETURN" + micAltUp ' Click Tab Key
Type micAltDwn + "TAB" + micAltUp    ' Click Enter\Return

If u Want to enter characters

 oShell.SendKeys "{h}"           ' Click h Key
 oShell.SendKeys "{i}"           ' Click i Key

 Type micAltDwn + "h" + micAltUp    ' Click h Key
 Type micAltDwn + "i" + micAltUp    ' Click i Key

WORKING FIDDLE

$(document).keyup(function (e) {
   $("#my_id").keyup(function (e) {
    if (e.keyCode == 13) {
        alert("Enter Simulated!!!")
       //your function goes here!!!
    }
});
    });

UPDATE:2nd demo

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