Forum Discussion

vbace2's avatar
Occasional Contributor
14 years ago

Object does not exist error handling / close IE

I apologize if this has been answered before, or if this can be found elsewhere.  I am a newbie to TC and I tried to search the help files and forums.

So, we purchased TC about 6 months ago, and we only had two test cases created.  The person who was using it before, and who had been trained on it, had their priorities/responsibilities changed.  So, I am the lucky one who is trying to utilize TC.  So, I wanted to start off with something simple.  I recorded a test that would start up a login page in IE, a user name and password is entered and the submit button is pressed.  The new page opens.  A web comparison is performed to make sure the correct place is reached.  The logout link is pressed.  Another web comparison is performed to make sure they were logged off.  This all seems to work fine.  When recorded, I selected to have this saved as JScript.

I went into the test and changed the password so that the user would not be able to log in successfully and get to the correct place.  When I run the test case, it waits for the login to process but then fails with "The object does not exist.  See Remarks for details."  The remarks say that an error occurred while call the "Wait" method or property of the "pageloginpage" object.  Of course this makes sense to me since it didn't get to the expected page.  When this happens, the test script ends and leaves IE open on the machine.

So, I tried using JScript try/catch to catch the error and then close IE.  If IE doesn't close, it causes issues when trying to run subsequent test cases.  It doesn't seem that the try catch gets executed when this runs.  I even tried the following to see if I was getting into the catch or finally blocks...

function test()


try {

all code here to open IE, try to login, etc. etc


catch(e) {

Log.Error("reached error");


finally {

Log.Message("reached finally");



If I have the correct password and the test goes through all the scripts, I get the message from the finally block.  However, if I have the wrong password and I get the "object does not exist" error, I don't get the catch message or the finally message.  It seems that TC job stops processing at that point.

So, is there a way to catch this error and perform processing (like closing IE)?


1 Reply

  • AlexKaras's avatar
    Champion Level 3
    Hi Dan,

    try/catch/finally handles runtime JScript errors (like using undeclared variable, array subscript out of range, null-pointer (de)referencing, etc.). In your case there is no runtime error but the code just attempts to call the method (.Wait() ) provided by TestComplete for the object (pageloginpage) that does not exist. As the method is provided by TestComplete, it is TestComplete that handles the problem of non-existing object and it is TestComplete that posts an error message to the log.

    You did not post your actual code, so I cannot correct some specific lines. But the recommended approach for the situations like this (i.e. when the target object might exist or not) is to get a reference to the object via its parent WaitWindow/WaitChild/WaitNamedChild/WaitAliasChild/WaitVCLObject/etc. method (depending on the object you are looking for and the type of the tested application) and then check the .Exists property of the returned object. See the relevant help topics (Exists, WaitWindow, etc.) for more details.

    Finally, your code should look like this (untested mockup):

    pageloginpage = parentObject.WaitNamedChild("pageloginpage", 500);

    if (pageloginpage.Exists)


      // actions for the login window




      // actions for the wrong login credentials


    Hope this will help...