When would you use the UITestControl.Find method?

核能气质少年 提交于 2019-12-08 07:50:49

问题


When checking whether a page/screen has loaded, I often use the UITestControl.WaitForControlExist() method, but I am finding example code that follows the ctl.WaitForControlExist() with otherCtl.Find() calls on the parent controls. Like this:

var tab = UIMainMenuExtWindow.UIItemWindow.UIRibbonClient.UISolutionsTabPage;
tab.WaitForControlExist(3000);
UIMainMenuExtWindow.Find();
UIMainMenuExtWindow.UIItemWindow.Find();
UIMainMenuExtWindow.UIItemWindow.UIRibbonClient.Find();
UIMainMenuExtWindow.UIItemWindow.UIRibbonClient.UISolutionsTabPage.Find();
tab.Find();
Mouse.Click(tab);

Does this code make sense? What is the purpose of the 'Find()' calls?


回答1:


After setting the SearchProperties and FilterProperties etc for a UI Control, the Find method causes the search to be performed. Commonly the Find is not called explicitly but it (or possibly some equivalent internal method) is called implicitly when the UI Control is evaluated in an expression as the parent of another control.

Consider:

this.uimap.uiTopLevel.ActionMethod();

In the above statement the value of uiTopLevel must be evaluated to find the object whose ActionMethod can be called. That evaluation requires the Find method.

The Find method may need to be called explicitly when an application replaces part of its display with another identical copy. The UI Controls, when first evaluated, get a reference to the original copy of the control. When the test tries to access the second version it may get a "control not found" or "hidden control" exception (forget the exact terminology of these exceptions). By re-evaluating the control, ie by calling the Find method explicitly, the new version of the control can be found.



来源:https://stackoverflow.com/questions/23937422/when-would-you-use-the-uitestcontrol-find-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!