Here is the code:
Code: Select all
private static Ranorex.Form WaitForFormOfForm(Ranorex.Form ParentRanorexFormName, string strFormName, int Timeout)
{
/************************************************************************
* Function : WaitForFormOfForm(Ranorex.Form ParentRanorexFormName, string strFormName, int Timeout)
*
* Description : This function will wait for a form with a specific
* : control name that is a child of a parent form to appear.
*
* Parameters : ParentRanorexFormName - Parent form to look in
* : strFormName - Control name of the form to find
* : Timeout - Time (in seconds) to wait for the window
* - before giving up.
*
* Return Type : Ranorex.Form
*
* Return Value : Ranorex.Form Object for success, null for failure
*
* Revision History
* Date : Author : Reason/Change
* ---------- : ------------------------- : ------------------------------
* 06/09/2009 : Chris Gendreau : Initial Creation
************************************************************************/
Ranorex.Form HDForm = null;
Report.Debug("Waiting for form: " + strFormName + " within form: " + ParentRanorexFormName.Element.GetAttributeValue("ControlName").ToString());
try
{
HDForm = ParentRanorexFormName.FindSingle(".//form[@controlname='" + strFormName + "']", Timeout * 1000);
HDForm.Activate();
Thread.Sleep(1000);
return HDForm;
}
catch (RanorexException e)
{
try
{
Thread.Sleep(5000);
HDForm = ParentRanorexFormName.FindSingle(".//form[@controlname='" + strFormName + "']", Timeout * 1000);
HDForm.Activate();
Thread.Sleep(1000);
return HDForm;
}
catch (RanorexException ex)
{
Report.Debug("Unable to find form: " + strFormName + " within form: " + ParentRanorexFormName.Element.GetAttributeValue("ControlName").ToString());
return null;
}
}
} //End WaitForFormOfForm
Can you offer any suggestions as to how to increase the reliability of this method?
Thanks!