Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
7 years ago

A condition in the if statement is causing problem

Hi, 

I'm writing a script to test a java client. There's a dialog recognized as an SWTObject.

If the dialog is not present, 'else' block  in the  following code should be executed, but something else is happening.

 

if(Aliases.javaw.SWTObject("Shell", "Primary : *").Exists){
Log.Message("Dialog found");
}else{ 
Log.Message("Dialog not found");
}

Here, if the object is present on the app, then it just works fine, but if the SWTObject is not present it throws this error instead of executing the 'else' block.  

 

Unable to find the object SWTObject("Shell", "Primary : *"). See Additional Information for details.

I don't understand this behaviour. Could someone please help? 

 

Thank you

Abhi

  • cunderw's avatar
    cunderw
    7 years ago

    The exists method could be used if the object is mapped though, or using WaitProperty. 

  • Hi Abhi,

     

    Replace SWTObject() call in your code with WaitSWTObject() one.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Abhi,

     

    Replace SWTObject() call in your code with WaitSWTObject() one.

     

    • Adagio's avatar
      Adagio
      Frequent Contributor

      Thank you, Alex..that works perfectly well.

       

      Thank you

      Abhi

  • Please try VisibleOnScreen property instead of Exists or try with Aliases.javaw.Findchild(propname,prop value,20) .

     

    Thanks ,

    Ashok

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Definitely use FindChild.  You can't call the "Exists" property of an object that does not exist.  FindChild, if it cannot find the object, returns an empty object with an Exist property with a value of false.

      • cunderw's avatar
        cunderw
        Community Hero

        The exists method could be used if the object is mapped though, or using WaitProperty.