Forum Discussion

Lee_M's avatar
Lee_M
Community Hero
2 years ago

If Object exists - Script and Keyword

HI,   The IF Object in either script or Keywords tests is not reliable for me.   When using ".Exists" or KW equivalent the code will execute and may bring back the correct results but the iss...
  • rraghvani's avatar
    2 years ago

    I've always found this annoying and confusing. When using Exists, we're checking the objects property value is either true or false (the object must not be null). But to validate the object state, you may need to check if the object exists in the system. Using the appropriate WaitNNN method, such as WaitChild method, gets around this problem.

     

    Here's an example, using WaitChild to find a button which doesn't exist. 

    It's not possible to use,

     

    if (btn !== null)
    // or
    if (btn != null)

     

    because WaitChild method is returning a stub object, btn will not be null.