Ask a Question

Object not found - continue with excecution

skolla
Frequent Visitor

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 1
AlexKaras
Champion Level 2

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();

 

 

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: