Forum Discussion

schwarz's avatar
schwarz
Occasional Contributor
9 years ago

Problem accessing mainform window

Hi all!

 

Since we migrated our testing machines to Windows10, we sometimes encounter problems using TestExecute (v11.31).

After our application is started, the mainform does not seem to have the focus.

Calling the SetFocus() method on the mainform results in this error:

"The window cannot get focus."

Calling Sys.Desktop.ActiveWindow() results in an exception

"Cannot find the window with handle 1234."

 

Once this error occurs, it is a permanent error (when I try Sys.Desktop.ActiveWindow() again after a minute, it will result in the same error).

It is not always reproducable.

I do not see anything else on the Win desktop except for the main window of our application. I'm not sure if Win10 causes this problem or not, but I think we did not see this on Win8.1.

 

Does anyone have an idea what may cause this?

 

Best regards

 

Jens Schwarz

 

  • Hi Jens,

     

    I hope that you with Support guys will solve this problem. Just a quick note though: Window objects (what forms are) cannot get focus indeed. It is controls on the form that usually can be focused. Windows/forms must be activated instead using the .Activate() method.

    Far not sure that this might help, but anyway...

  • schwarz's avatar
    schwarz
    9 years ago

    Hi Alex,

     

    Thanks for your reply, it´s the same that we were advised by the support team. SetFocus() on a form works for us usually - but not in this case. It's no problem to use Activate() instead of SetFocus(), but it bothers me a bit that we have to use Activate() everytime when we start a tested app to prevent that occasional error.

    Anyway, it is working now.

     

    Thanks...

     

    Best regards

     

    Jens Schwarz

  • Sebastian49's avatar
    Sebastian49
    Occasional Contributor

    Hi schwarz,

     

    Is your Problem still existent?

    Which properties did you use to map your window in the NameMapping?

     

    I think some properties may not be constant in different runs or may have change with Windows 10.

     

    It would be great if you could provide the mapping info of your testet window.

     

     

    Regards Sebastian

     

     

     

      

    • schwarz's avatar
      schwarz
      Occasional Contributor

      Yes, the problem still exists. We've already contacted Smartbear Support to find a solution.

       

      We do not use name mapping at all.

       

      Best regards

       

      Jens Schwarz

       

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Jens,

     

    I hope that you with Support guys will solve this problem. Just a quick note though: Window objects (what forms are) cannot get focus indeed. It is controls on the form that usually can be focused. Windows/forms must be activated instead using the .Activate() method.

    Far not sure that this might help, but anyway...

    • schwarz's avatar
      schwarz
      Occasional Contributor

      Hi Alex,

       

      Thanks for your reply, it´s the same that we were advised by the support team. SetFocus() on a form works for us usually - but not in this case. It's no problem to use Activate() instead of SetFocus(), but it bothers me a bit that we have to use Activate() everytime when we start a tested app to prevent that occasional error.

      Anyway, it is working now.

       

      Thanks...

       

      Best regards

       

      Jens Schwarz

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi Jens,

         

        Thank you for the update.

        Actually, I am a bit wondered that SetFocus() applied to the window/form worked for you on some environment...

        I used to call .Activate() for application windows before using them because if the window cannot be activated (effectively - put on top of all windows) then the OnUnexpectedWindow event will be triggered in TestComplete. This can happen if some unexpected modal window was left on the screen after the previous actions. Handling the OnUnexpectedEvent it is possible to process this blocking modal window and make it possible for the test run to continue but not fail.