Forum Discussion

glarsen_1's avatar
glarsen_1
Occasional Contributor
12 years ago

If... Statements


Whenever i write an If.. Statment to check if a dialog window exists, it always tells me that there is an error:



For Example:

Sub Test

 Call Sys.Process("xms").Window("#32770", "*").Window("Button", "OK").ClickButton

 

 If Sys.Process("xms").Window("#32770", "Times Series Plot", 1).Exists Then

  Log.Message("This Is a Bug and We Need To Report It")

 End If

 

 Call....(continue the test)

 

Now This is causing problems cause i don't want it to show an error but if the window isn't there, it logs an error.


  • sastowe's avatar
    sastowe
    Super Contributor
    This actually won't work:



    If Sys.Process("xms").Window("#32770", "Times Series Plot", 1).Exists Then



    If the window .Window("#32770", "Times Series Plot", 1), does exist, then clearly its proprties are available including the Exists property. But if it does not exist, then there is no object to check the exists property of.



    Instead



    If Sys.Process("xms").WaitWindow("#32770", "Times Series Plot", 1, iWhatever).Exists Then



    The WaitXXX methods will return an object with at the very least the Exists property. If the wait does not find the desired window, then the exists is false.
  • paul_scroce's avatar
    paul_scroce
    Frequent Contributor
    Can you check in the object browser if the Window still exists but the visible propertry is false?
  • mark_addinall's avatar
    mark_addinall
    Occasional Contributor
    The previous poster is correct, using the WaitWindow method is the way to go. Check the properties of the window you are looking for using the object spy.
  • glarsen_1's avatar
    glarsen_1
    Occasional Contributor
    I understand that it should work, the problem is its not. When the window doesn't exist it hangs and tells me it can't find the window. But the if statement should make it skip the line if it can't find it. even with the wait window it hung.
  • Hey,

    Could you post the errors its giving?

    Also is it giving the error at the if statement or is it the line above it? 



    Sub Test

     Call Sys.Process("xms").Window("#32770", "*").Window("Button", "OK").ClickButton     <<<---- this one?

     

     If Sys.Process("xms").Window("#32770", "Times Series Plot", 1).Exists Then

      Log.Message("This Is a Bug and We Need To Report It")

     End If

     



    also you may need WaitProcess too 

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



     
  • sastowe's avatar
    sastowe
    Super Contributor
    Repost the new code with the WAITWindow in use so we can help see where the issue lies.



    S
  • Ravik's avatar
    Ravik
    Super Contributor
    Hi Gage Larsen,



    Actually Exist method make more confusion in TestCompelete.



    You have check-



    If Sys.Process("xms").Window("#32770", "Times Series Plot", 1).Exists Then

      Log.Message("This Is a Bug and We Need To Report It")

     End If




    Suppose, your pop-up will not appearing then script is still waiting for execution of your above code. becouse the execution flow come Top to bottom, hence it's get fail.



    Here Exist method completely different from QTP.