2

我遇到了与模态窗口有关的问题。

在我正在自动化的应用程序中,如果用户有一些数据,则会打开一个模式窗口,但如果没有,则不会打开。我们如何放置“if 语句”,例如,如果模态窗口存在则做一些工作,否则跳过。因为我在这个声明中有一个错误

Window childWindow = mainWindow.ModalWindow("child");

它抛出异常,因为它无法搜索名称为“child”的窗口。我知道它不存在。如果它不存在,它应该跳过它。

4

2 回答 2

4

在执行 ModalWindow 方法之前,您可以尝试查看是否有任何模态窗口

Window childWindow = null;
if(mainWindow.ModalWindows().Any())
{
    childWindow = mainWindow.ModalWindow("child");
}

否则您可以尝试定义标准,或者在某个超时时

...
var timer = new StopWatch();
timer.Start();
Window childWindow = null;
do 
{
    childWindow = mainWindow.ModalWindow("child");
} while (childWindow != null || timer.ElapsedMilliseconds < timeOutInMs);
...

希望能帮助到你。

里克

于 2015-02-10T10:23:07.153 回答
0

我的工作代码(AutomationUI):

using System.Windows.Automation;

Automation.AddAutomationEventHandler(
            WindowPattern.WindowOpenedEvent,
            mainWindow.AutomationElement,
            TreeScope.Descendants,
            (sender, e) =>
            {
                var element = sender as AutomationElement;
                if (!(element.Current.LocalizedControlType == "Dialog" && element.Current.Name == "modalWindowTitle"))
                    return;

                Automation.RemoveAllEventHandlers();
                // Here run your code. The modal window was opened
            });
于 2017-02-22T09:16:22.693 回答