Forum Discussion

joffre's avatar
joffre
Regular Contributor
13 years ago

Check if window exists

How can I check if a window exists or not?



The window's full name is:

Sys.Process("FPw5").Window("#32770", "FPW : Mensagem", 1)




It may or may not be shown, depending on the options that I selected before.



If I do like this...

wdwMsg = Sys.Process("FPw5").Window("#32770", "FPW : Mensagem", 1);

if (wdwMsg.Exists) {

 MessageDlg("An error happenned. Check Logs for more information!", mtError, mbOK, 0);

 Log.Error(wdwMsg.WndCaption);

 Runner.Stop();

}




...and the window isn't shown, an error will return to Log beucase the window wasn't found.



How can I check if the window exists not receiving the "window does not exist" error?

3 Replies

  • Hey, 



    I think you can use waitwindow.

    I think that  using this method means that if the window doesn't exist, It will return a stub rather than an error

    http://support.smartbear.com/viewarticle/30939/



    s
    omething like 



    p = Sys.Process("Notepad");

    // Waits for the window for 10 seconds

    w = p.WaitWindow("*", "Open*", -1, 10000);

    if (w.Exists)

    {

    //do something 

     }



      
  • joffre's avatar
    joffre
    Regular Contributor


    Hello KimPenta. Thanks for your quick response.



    I've tried like this:

    {

      wdwMsg = Sys.Process("FPw5").Window("#32770", "FPW : Mensagem", 1);

      timeout = wdwMsg.WaitWindow("*", "*", -1, 1000)

      if (timeout.Exists) {

       MessageDlg("An error happenned. Check Logs for more information!", mtError, mbOK, 0);

        wdwMsgResult = Sys.Process("FPw5").Window("#32770", "FPW : Mensagem", 1).Window("Static", "*", 2);

       Log.Error(wdwMsgResult.WndCaption);

       Runner.Stop();

      }

    }



    And received the following error log:

    Cannot obtain the window with the window class '#32770', window caption 'FPW : Mensagem' and index 1. See Additional Information for details.


    On Additional Info says that "The window with the specified attributes does not exist"



    Double click on the LogError moved me to the line where I am creating the wdwMsg variable:



    wdwMsg = Sys.Process("FPw5").Window("#32770", "FPW : Mensagem", 1);



    Hope you can help me.


  • joffre's avatar
    joffre
    Regular Contributor
    Problem solved!



    {

      frmSplash = Sys.Process("FPw5").WaitChild("*frmSplash*", 1000);

      while (frmSplash.Exists) {

        Delay(500);

      }

    }




    There is nothing like a little patience and a lot of persistence!



    Thanks for your help!