Forum Discussion

kandy1984's avatar
kandy1984
Contributor
7 years ago

Scripting to continue with popup window

Hi,

 

I am having trouble to write a vbscript which  checks if the pop-up window has appeared and then if its there, then click on "Cancel" button and if its not there, then procced to the next testscript. I have wrote as below,

 

if Aliases.DataAcquisition.WinFormsObject("AutomatedStatusChangeUIControl").Exists Then
             Aliases.DataAcquisition.WinFormsObject("AutomatedStatusChangeUIControl").WinFormsObject("btnCancel").ClickButton
Else

 

Call Test 1

 

 end if

 

 

The problem here is that, if the "AutomatedStatusChangeUIControl" does now appear, its always giving an error. How can i make it skip the window popup can continue.

 

Thanks for  helping,

Sudha

  • This is a common mistake.  If you think about it, how do you check the "Exists" property of an object that does not exist?  If the object does not exist, it won't even have an "Exists" property.  So, you need to first attempt to locate the object.  That is done using either a Wait method or a Find method.  Taking your code from below, I would use WaitWinFormsObject (https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/waitwinformsobject-method.html).  HEre's how I'd change your code.

     

    if Aliases.DataAcquisition.WaitWinFormsObject("AutomatedStatusChangeUIControl", 5000).Exists Then
                 Aliases.DataAcquisition.WinFormsObject("AutomatedStatusChangeUIControl").WinFormsObject("btnCancel").ClickButton
    Else 
    
    Call Test 1
    
     end if
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    This is a common mistake.  If you think about it, how do you check the "Exists" property of an object that does not exist?  If the object does not exist, it won't even have an "Exists" property.  So, you need to first attempt to locate the object.  That is done using either a Wait method or a Find method.  Taking your code from below, I would use WaitWinFormsObject (https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/waitwinformsobject-method.html).  HEre's how I'd change your code.

     

    if Aliases.DataAcquisition.WaitWinFormsObject("AutomatedStatusChangeUIControl", 5000).Exists Then
                 Aliases.DataAcquisition.WinFormsObject("AutomatedStatusChangeUIControl").WinFormsObject("btnCancel").ClickButton
    Else 
    
    Call Test 1
    
     end if
    • kandy1984's avatar
      kandy1984
      Contributor

      Thank you Robert Martin. Now its working as expected.