Forum Discussion

skolla's avatar
skolla
Frequent Visitor
7 years ago

Object not found - continue with excecution

Greetings,

 

I am entering specific text in an input field and if the entered number is invalid an alert form will pop up and if not it wont.

my problem is that if it doesn't pop up test complete complains "object doesn't exist" and the aim is to continue with the execution if its not available, if it is available then i will dismiss the alert form by clicking "OK"

function genericAlertForm(ActionName) {

try{

  var b = context.get("genAlertForm");

  b = eval(b); //this is suppose to convert the path to an object but it fails on this line if the alert is not available

    if(b.Exists) {

        b.Button(ActionName);

        Log.Message(" ");

    } else {

        Log.Warning(" ");

    }

    }catch(e){

   Log.Warning("test")

}

}

 

I am testing a flash app.

 

b = eval(b);     <-- I still want Test Complete to execute the code but i do not want it ti fail/stop the script here if it does not find/convert the object. It must continue to execute if the object is not available.

 

 

1 Reply

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > var b = context.get("genAlertForm");

     

    a) The recommended way in TestComplete is to use its functionality to search for the objects rather then use internal page methods. (Guessing that you have either some Selenium background or page development experience)

    b) TestComplete provides a set of .FindXXX() methods that try to find an object but do not report a problem if the object was not found. Check TestComplete help for more details about .WaitXXX() methods.

     

    Assuming that genAlertForm is an identifier of the form, the code may be like this (untested sample with guessed parameters):

    var b = <testedPage>.WaitPanel("genAlertForm", 500); // check for 0.5 sec if alert panel was displayed

    if (b.Exists)

      b.Button("OK").Close(); // click OK button

    ...

     

    Two other notes about your code:

    1) eval() function evaluates the code presented as a string. But I think that context.get("genAlertForm") already returns some web element, but not the string. Correct usage must be like var b = eval('context.get("genAlertForm");');

    2) b.Button(ActionName); will not click a button (assuming that Button() is not a native method of the b object). The code should be like: b.Button("OK").Click();