Forum Discussion

ash10's avatar
ash10
Occasional Contributor
10 years ago
Solved

How to check if the window or object exsist

I have dialog1 appearing on my App sometime and if it appears then I have to click on Ok and  sometime this dialog might not appear. 

 

if(Aliases["App"]["WinFormsObject"]("Dialog1")["Exists"])
Aliases["App"]["WinFormsObject"]("Dialog1")["WinFormsObject"]("buttonClose")["Click"]()

 

I cannot us  "Exists" property  here on Dialog1 as Dialog1 will not be there if it does not appear.

I tried to put try catch block also but it is not handling the expection thrown try catch.

 

  • Use WaitWinFormsObject for Dialog1:

     

    var dlg = Aliases["App"]["WaitWinFormsObject"]("Dialog1", 1000);
    if (dlg.Exists)
      dlg["WinFormsObject"]("buttonClose")["Click"]();

     

5 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    did you tried waiteproperty..

    something like..   ("Dialog1").WaitProperty('Exists',true,1500)

    • ash10's avatar
      ash10
      Occasional Contributor

      Nope was Dialog1 does not exsists, If I use waitproperty then it gives a message that Unable to find the object Dialog1

    • ash10's avatar
      ash10
      Occasional Contributor

      Nope as Dialog1 does not exsists, If I use waitproperty on Dialog1

      like if(Aliases["App"]["WinFormsObject"]("Dialog1")["WaitProperty"]("Exists",True, 1000))

       Aliases["App"]["WinFormsObject"]("Dialog1")["WinFormsObject"]("buttonClose")["Click"]()

      then it gives a message that Unable to find the object  WinFormsObject("Dialog1")

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Use WaitWinFormsObject for Dialog1:

         

        var dlg = Aliases["App"]["WaitWinFormsObject"]("Dialog1", 1000);
        if (dlg.Exists)
          dlg["WinFormsObject"]("buttonClose")["Click"]();