Best way to test that something doesn't exist without an error
Morning all,
I have a piece of script that waits for the loading panel to disappear off the page. It's on the page 99% of the time, but not always. It always has the same name and location in the structure if it is on the page (browser->form->panel->LoadPanel Table) So I use a FindChild on the form to get my loading panel. While the loading panel is in the way, the VisibleOnScreen is true. As soon as it goes away, VisibleOnScreen changes to false. Very handy. Find it, getpropertyvalue in a loop with short interval and continue as soon as it changes. I don't need to tell any users anything. It's just that it's more efficient than building in a 5 second delay in case the panel is still there. In these situations TestComplete finds the Textbox/combobox/whatever I'm looking for and tries entering text because hey, it exists and is visible, but falls because it can't get focus...
I'm trying to avoid having to map this panel on ALL my pages, so my question comes on that 1% of pages where the table doesn't exist on the page at all. I want this function to just exit silently rather than error when the wait or find fails to find the object at all. Thoughts?
/// <summary> /// Waits for the Loading Panel to disappear off screen /// </summary> function WaitLoadExampple() { //panel hasn't been loaded before. First get it //But since it doesn't change, keep it in a variable //Not using .Exists, since it's a varaible which may not even be a stub yet if(Project.Variables.LoadingPanel==null || Project.Variables.LoadingPanel==undefined) { Delay(1000,"Load Panel exist load"); var formObj = Aliases.browser.FindChildEx("ObjectType","Form",2,true,5000); if(!formObj.Exists) { Log.Warning("WaitLoadingPanel() timed out while waiting for the form object","",pmNormal,"",GetPagePicture()); return; } Project.Variables.LoadingPanel = ExecuteWait("TABLE",formObj,"LoadingPanelTable"); //this does a WaitTable() in a loop if(!Project.Variables.LoadingPanel.Exists) { Log.Warning("WaitLoadingPanel() timed out while waiting for the table object","",pmNormal,"",GetPagePicture()); return; } } if(aqObject.IsSupported(Project.Variables.LoadingPanel,"VisibleOnScreen")) { var isVisible = aqObject.GetPropertyValue(Project.Variables.LoadingPanel,"VisibleOnScreen"); if(isVisible) Log.Message("***** Loading panel was visible on screen ****","",pmNormal,"",GetPagePicture()); var retries = 0; while(isVisible && retries < 100) { retries++; if(retries==2) Log.Message("***** WaitLoadingPanel() had to wait ****","",pmNormal,"",GetPagePicture()); if(Project.Variables.LoadingPanel.WaitProperty("VisibleOnScreen",false,100)) { Log.Message("***** WaitLoadingPanel() finished waiting ****","",pmNormal,"",GetPagePicture()); break; } } } return; }