Forum Discussion

SJ1's avatar
SJ1
Occasional Contributor
6 years ago
Solved

Unable to handle the error using the script: "Unable to find the object"

Hi, I am trying to automate oracle forms application.

 

The script I have written searches for the window object. If its found, it logs "window found" else it should say "not found". Btw, i am storing the objects in XML as strings and using eval to convert to object,

 

The script works fine when it finds the window object. In negative scenario, where the window object is not available, it abruptly terminates the execution flow with the message written to log: "Unable to find the object AWTObject("FWindow", "No Results Found", 0). See Additional Information for details." 

 

Instead I would expect the script to handle this error and get into the else part to display the message. [Note: I have not enabled Stop on Error in project properties]

 

Can you please help me with the code to handle this object not found error which is thrown during the script execution?

 

Please find the script below:

 

function Window_NoResultsFound()
{
var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
if(noResultsFoundAlert.VisibleOnScreen)
{
Log.Message("window displayed")
}
else
{
Log.Error("window not displayed");
}
}

 

 

  • Below approach is not recommended by many users but based on the flow this will work.

     

    function Window_NoResultsFound() {
        var noResultsFoundAlert = null;
        try{
            noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
        }catch(ex){
            //if you want you can Log.erro here too
        }
        if (noResultsFoundAlert == null) {
            Log.Checkpoint("Window is not displayed as expected.")    
        } else {
            if (noResultsFoundAlert.Exists) {
                Log.Error("Windows is displayed");
            } else {
                Log.Checkpoint("Window is not displayed as expected.");
            }
        }
    }

10 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    I would recommend checking Exists before checking any other properties.

    Like below,

    function Window_NoResultsFound() {
        var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
        if (noResultsFoundAlert.Exists) {
            if (noResultsFoundAlert.VisibleOnScreen) {
                Log.Message("window displayed")
            } else {
                Log.Error("window not displayed");
            }
        } else {
            Log.Error("window not displayed");
        }
    }
    • SJ1's avatar
      SJ1
      Occasional Contributor

      Thank you AlexKaras and Shankar for your time.

      Unfortunately these options doesn't seem to work.

      1. Stop On Error: Is not turned on
      2. WaitAWTObject: didn't work
      3. Exists : doesn't seem to work

       

      Looks like the script fails even before using these commands, where TestComplete tries to look for the object once its defined, once it hits the below line:
      var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);

       

      I have also tried declaring the object directly in the script and not in xml. That doesn't seem to work as well.
      var noResultsFoundAlert = Aliases.jp2launcher.SwingObject("......");

       

      The moment the object is declared, TestComplete tries to look for it and fails it straight away in runtime before moving onto the next statements/conditions.

       

      Any other solutions would be much appreciated.

      • shankar_r's avatar
        shankar_r
        Community Hero

        One thing you have to keep in mind,


        var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);

        OR

        var noResultsFoundAlert = Aliases.jp2launcher.SwingObject("......");


        The object should be available when the script comes to above line(s), If object not found then it will immediately throw an error.

        You have to wait until the object became exists using WaitProperty.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Most probably, the reasons are:

    1) You have 'Stop On Error' option turned on in the runtime properties of your project;

    2) As a part of the string used in eval() you are having something like AWTObject(...). AWTObject must be replaced with its WaitXXX version: WaitAWTObject(...) - see documentation for the list of function parameters.