public static GuiFileDialog Find(AutomationElement window, string caption) { int maxRetries = UiTestDslCoreCommon.MaxConnectionRetries; AutomationElement res = null; while (window == null && maxRetries > 0) { try { window = window.FindChildByLocalizedControlTypeAndName(caption, "Dialog"); } catch (Exception) { if (maxRetries > 0) maxRetries--; else throw; } if (window == null) Thread.Sleep(500); maxRetries--; } Thread.Sleep(500); return new GuiFileDialog(res, window, caption); }