Forum Discussion

davemcauley's avatar
davemcauley
New Contributor
3 years ago
Solved

Desktop Driver Key Board operations dont seem to work with swing.

Desktop Driver Key Board operations dont seem to work with swing.

 

Trying driver.getDesktop().keys("[Tab]") operation while in a text box but nothing happens.

  • AlexKaras's avatar
    AlexKaras
    3 years ago

    Hi David,

     

    how then can you tab to different parts with in your application if that is what is required?

    Not sure if I got your question right...

    I have much more experience with TestComplete but not with TestLeft, but, considering that TestLeft is based on TestComplete's engine, I believe that the described functionality will match.

    So, when you write test code, you usually know what window/object you need to interact with and usually the code looks like driver.Window(...).Control(...).Keys(...).

    If some window must be activated (i.e. put into foreground), then its .Activate() method should be used.

    .Keys() method basically puts specified string into the message queue of referenced window/control. How the queue is dispatched and processed is determined by the OS and the application itself.

    For example, the input put into the window message queue can be dispatched first to the active focused control and then, if not processed, to the window itself.

     

    To summarize: explicit reference to windows/controls improves reliability of test code. Sending keys to desktop (or, say, main application's window) might work but with much less reliability and the result of the execution will depend on the current system's state. (For example, unexpected notification window might break the whole test.)

     

    Does this answer your question somehow?

     

5 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Might it be because 'Tab' is processed by the desktop but not the tested application?

    (In my case, the Start button becomes selected when I manually click somewhere on the desktop and press Tab key.)

     

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi David,

         

        the tab operation is not perfromed

        And what are your expectations from execution of the

        driver.getDesktop().keys("[Tab]")

        code line?

        (Note, that most probably (as I do not know your code), the focus moves to some other window and thus I am not sure that you can observe the result of this code line execution.)

         

        Update:

        I am not using Java, so I tried your code with C#.

        When running under debugger I also did not see any evidence of code execution. But when I started code without debugger, I clearly saw that Tab was processed by the application's window:

        AlexKaras_0-1628524750714.png