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."); } } }