Search code examples
javascriptqtphp-uft

How do you simulate a keyboard enter event in UFT


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?

I have tried

field1.Set Chr(13)

field1.FireEvent "onkeydown"

but it doesn't trigger the event.

I am trying aviod using the SendKeys command.


Solution

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