我正面临编码 UI 的 WaitForControlExist() 函数的奇怪行为。第二次查询时,即使控件存在,值也会返回false。这是Coded UI的预期行为吗?我的程序看起来类似于下面..
//A sample program that Checks for Run window when "Windows + R" key is pressed
public void TestFunction()
{
bool isExists = false;
#region Variable Declarations
UIMap uiMap = new UIMap();
WinWindow uIRunWindow = uiMap.UIRunWindow;
WinComboBox uIOpenComboBox = uiMap.UIRunWindow.UIItemWindow.UIOpenComboBox;
WinButton uICancelButton = uiMap.UIRunWindow.UICancelWindow.UICancelButton;
#endregion
//1st Run
Keyboard.SendKeys("R", ModifierKeys.Windows);
isExists = uIRunWindow.WaitForControlExist(7000);
Console.WriteLine("Is Run Window Appears :: " + isExists);
Mouse.Click(uICancelButton);
Playback.Wait(2000);
isExists = uIRunWindow.WaitForControlNotExist(7000);
Console.WriteLine("Is Run Window Closes :: " + isExists);
//2nd Run
Keyboard.SendKeys("R", ModifierKeys.Windows);
isExists = uIRunWindow.WaitForControlExist(7000);
Console.WriteLine("Run Window Appears :: " + isExists);
Mouse.Click(uICancelButton);
Playback.Wait(2000);
isExists = uIRunWindow.WaitForControlNotExist(7000);
Console.WriteLine("Is Run Window Closes :: " + isExists);
}
在上面的程序中,在第二次运行事件期间,虽然运行窗口存在,但该值返回为 false。
我遇到的解决方法是在第一次和第二次运行中使用 2 个不同的对象,或者重新初始化 UIMap 对象,如下所示
如果在这种情况下有任何其他解决方案或最佳实践,请帮助我