cancel
Showing results for 
Search instead for 
Did you mean: 

TestComplete will not go to Else - just throws error

SOLVED
Highlighted
Occasional Contributor

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")

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: TestComplete will not go to Else - just throws error

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")

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
3 REPLIES 3
Community Hero

Re: TestComplete will not go to Else - just throws error

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")

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: TestComplete will not go to Else - just throws error

Thanks will try and let you know. 

Community Hero

Re: TestComplete will not go to Else - just throws error

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors