Forum Discussion

jhaney's avatar
jhaney
New Contributor
12 years ago

What else is .Keys doing besides entering characters?


I have an application that I'm testing that uses AJAX to perform validation and perform other events once a value is entered in a field. If I manually type a value in the field, and tab off, the validation and events happen normally. If I use TestComplete (v 10.20.953.7) to enter the value in the field using .Keys, the value is entered in the field and then some other event occurs, triggering the validation (incorrectly for some reason). I'm then doing a .Keys "[Tab]" but that then puts the focus back in the field, (causing another validation error in the field that the focus was just in). I tried using SetText, but that isn't simulating the keystrokes that the app is requiring to trigger the AJAX for some reason. I'm sure there's a problem with the application not handling events correctly, but I need to understand what's going on so that I can have an educated discussion with the developer about what's going wrong.



So my question is, what is .Keys doing after it enters values in the field, and why is it doing more than just that and not leaving the cursor after the last entered character to more closely simulate user interaction?



Thanks in advance for any ressponse. I tried searching for this topic and didn't really come up with anything that answered my question.



Regards,



Joel


3 Replies

  • Hi Joel,



    There could be couple of suggestions.



    1. Have you tried immediately performing the next operation after keys method instead of tabbing out. It may happen that before you tab out, the curson goes to some other field and then when you tab out, the focus goes back to the first field. And then next field might be yours which gets focus back again.



    2.  Have you tried using Esc key which might allow the field to be out of focus and trigger required validations.



    Thansk

  • jhaney's avatar
    jhaney
    New Contributor
    Thanks for your reply Shrirang.



    1. Yes. Unfortunately, there is something going on in .Keys that is different from manual user interaction with the field. If I do <myobject>.Keys "1234", 1234 is entered in the field and the validation is immediately triggered that populates other fields (incorrectly, for reasons I'm still trying to understand with our dev) before moving on to the next TC line. If I manually enter 1234 in the field, no validation takes place until after I move out of the field. This tells me that once .Keys is done entering the specified value, it's doing more and leaving the field, or removing focus at least, causing the event to be triggered.



    2. I tried <myobject>.Keys "1234" & "[Esc]". Did not change the outcome.



    Thank you for your suggestions. I think the issue is that .Keys is doing more than just entering values and until I know what that extra action is, I won't be able to have a discussion with our devs to maybe have that event/action added to what triggers the correct validation/population.



    Thanks again,

    Joel
  • Hi Joel,



    I can think of an alternative to use KeyPressUp, KeyPressDown methods to simulate particular keys. This would be little lengthy but might avoid from triggering your functional validations.



    The Keys method internally simulates the same thing like



    For Ex-

    TestObj.Keys("123")



    Then it would be something like

    TestObj.KeyPressDown("1")

    TestObj.KeyPressUp("1")

    TestObj.KeyPressDown("2")

    TestObj.KeyPressUp("2")

    TestObj.KeyPressDown("3")

    TestObj.KeyPressUp("3")



    But you don't have control on individual key press events.



    If you individually use these methods, it may not trigger the validations.



    Good luck.