Forum Discussion

mgreen's avatar
mgreen
Contributor
6 years ago

TestComplete will not go to Else - just throws error

Been experiencing some wierd issues with my IF statements lately in testcomplete.. 

IF the statement IS NOT true I will get an extremely long hang/timeout, or in this case with the code below, I will just get a error in log saying "object doesnt exist" when it is obvious that I want it to go to ELSE.

 

Any advice for this?  thanks

 

if (Aliases.browser.webpage.cell0_grid.link.VisibleOnScreen == true)
{
Log.Message("Item ID is visible on screen")
} else {
Log.Message("Item ID is NOT on screen")

  • If the object does not exist, the first thing that it will attempt is to check existance before it attempts the "else".  That's why you're getting that error.  If there is the liklihood that an object may not exist when you go to access it, you should always check for existance first before you perform the action.  "VisibleOnScreen" might not be the best property to check in your case. Exists migtht be a better check.  Try the following code.

     

    if (Aliases.browser.webpage.cell0_grid.WaitAliasChild('link', 30000).Exists)
    {
    Log.Message("Item ID is visible on screen") 
    } else {
    Log.Message("Item ID is NOT on screen")
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    If the object does not exist, the first thing that it will attempt is to check existance before it attempts the "else".  That's why you're getting that error.  If there is the liklihood that an object may not exist when you go to access it, you should always check for existance first before you perform the action.  "VisibleOnScreen" might not be the best property to check in your case. Exists migtht be a better check.  Try the following code.

     

    if (Aliases.browser.webpage.cell0_grid.WaitAliasChild('link', 30000).Exists)
    {
    Log.Message("Item ID is visible on screen") 
    } else {
    Log.Message("Item ID is NOT on screen")
    • mgreen's avatar
      mgreen
      Contributor

      Thanks will try and let you know. 

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Alternatively, you could do that check for existance and then, nested in it, a check for visibility... that MIGHT be the better solution in the long run but it seems the existance check is your first step.