Forum Discussion

Diceman's avatar
Diceman
Occasional Contributor
8 years ago
Solved

Page not found leads to "Object Required" Error. How to execute alternative steps instead?

Given the following code, I am able to open Internet Explorer to "about:blank" and the script, when run, will log a 1.   However, if I change the page to an alternative page, the function crashes.   I cannot get it to log a 2.   How do I have TestComplete perform some alternative steps in the event that a page doesn't exist?

 

function Test(){
if(Sys.Browser("iexplore").Page("about:blank").Exists)
{
Log.Message("1");
}
else{
Log.Message("2");
}
}

  •  

    The problem is TestComplete looks for the exist property of  Page("about:blank") it's there so you get log 1

    But when TC looks for exist property of Page("alternative page") , it is looking a property in non existant object. so it crash.

     

    To avode that you can use "WaitAliasChild" Method this will waite for defined time and then 

    If the specified object does not exist, the method returns a stub object with "exist =False"

     

    you can arrange your function like below

    function Test(){
    if(Sys.Browser("iexplore").WaitAliasChild("alternative page", 10000).Exists )
    {
    Log.Message("1");
    }
    else{
    Log.Message("2");
    }
    }

    However you may have to map the "alternative page" in name mappings.

     

    If calling URL you can use  TestObj.WaitPage(URLTimeout) method.

     

    for more information pl refer...this and this

3 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

     

    The problem is TestComplete looks for the exist property of  Page("about:blank") it's there so you get log 1

    But when TC looks for exist property of Page("alternative page") , it is looking a property in non existant object. so it crash.

     

    To avode that you can use "WaitAliasChild" Method this will waite for defined time and then 

    If the specified object does not exist, the method returns a stub object with "exist =False"

     

    you can arrange your function like below

    function Test(){
    if(Sys.Browser("iexplore").WaitAliasChild("alternative page", 10000).Exists )
    {
    Log.Message("1");
    }
    else{
    Log.Message("2");
    }
    }

    However you may have to map the "alternative page" in name mappings.

     

    If calling URL you can use  TestObj.WaitPage(URLTimeout) method.

     

    for more information pl refer...this and this

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Minor correction, since the code doesn't use Aliases, WaitPage is the better method since you are SPECIFICALLY waiting for a page

       

      But then, to totally turn that into a universal function to use for ANYTHING

       

       

      function WaitForMyPage(pageUrl){
      if(Sys.Browser("iexplore").WaitPage(pageUrl, 1, 10000).Exists )
      {
      Log.Message("1");
      }
      else{
      Log.Message("2");
      }
      }
      
      function foo(){
         WaitForMyPage('http://www.google.com/'); //will log a 1 if the google page is open, 2 if anything else is open
      }