Forum Discussion

sangmook's avatar
sangmook
Occasional Contributor
7 years ago

Questions about Checking Whether an Object Exists

I want to use

 

"Checking Whether an Object Exists"

 

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

 

API for checking weather after clicking a button, the next page shows up right or not.

 

If a sentence which is supposed to be in the page that I want, it will be "success"

 

Do you think this is proper use of API?

 

Acutally I have no experience about this area, I'm really newbie here.

 

Please let me know if there is better option for checking the right value.

5 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    Basically, you want check whether an object displayed in the screen or not. This doesn't require any API if you are using Test Complete.

     

    you can use like below,

    function testSample()
    {
             if(Sys.Process("notepad").Exists)
             {
                   Log.Message("Object exists in the screen");
             }
             else
             {
                   Log.Error("Object not exists");
             }
    }

     

    To verify the object property you can use https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.html

     

    Also, take a Test Complete 101 training or see the existing video here for better understanding of Test Complete.

    • Bobik's avatar
      Bobik
      Frequent Contributor

      Correct code:

      function testSample()
      {
               if(Sys.WaitProcess("notepad").Exists)
               {
                     Log.Message("Object exists");
               }
               else
               {
                     Log.Error("Object not exists");
               }
      }

      Call Sys.Process("notepad") will cause an error when object doesn't exist. And script will fail before your "Else" block.  So you have to  use "WaitProcess" method.

      • shankar_r's avatar
        shankar_r
        Community Hero

        Bobik I agree, else block will not run if Stop On Error is checked but it will run when Stop On Error is unchecked. :)