[英]UI Automation with White issue finding childs
出于某种原因,当尝试从其父级中找到Window子级时,我从White.Core收到运行时错误。
显示错误:
White.Core.Mappings.ControlDictionaryException: Could not find TestControl for ControlType=window and FrameworkId:Win32
at White.Core.Mappings.ControlDictionary.GetTestControlType(ControlType controlType, String frameWorkId, Boolean isNativeControl)
at White.Core.Mappings.ControlDictionary.GetTestType(String className, ControlType controlType, String frameworkId, String name, Boolean isNativeControl)
at White.Core.Mappings.ControlDictionary.GetTestType(AutomationElement automationElement)
at White.Core.Factory.DictionaryMappedItemFactory.Create(AutomationElement automationElement, ActionListener actionListener)
at White.Core.Factory.DictionaryMappedItemFactory.Create(AutomationElement automationElement, ActionListener actionListener, Type customItemType)
at White.Core.Factory.PrimaryUIItemFactory.Create(SearchCriteria searchCriteria, ActionListener actionListener)
at White.Core.UIItems.Container.NonCachedContainerItemFactory.Find(SearchCriteria searchCriteria)
at White.Core.UIItems.Container.ContainerItemFactory.Get(SearchCriteria searchCriteria, ActionListener uiItemActionListener)
at White.Core.Sessions.NullWindowSession.Get(ContainerItemFactory containerItemFactory, SearchCriteria searchCriteria, ActionListener actionListener)
at White.Core.UIItems.Container.CurrentContainerItemFactory.Find(SearchCriteria searchCriteria, WindowSession windowSession)
at White.Core.UIItems.UIItemContainer.Get(SearchCriteria searchCriteria)
--- End of inner exception stack trace ---
at White.Core.UIItems.UIItemContainer.Get(SearchCriteria searchCriteria)
at ICOWrapper.Form1.wasUserLoggedIn(String id1, String id2)
at ICOWrapper.Form1.button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我尝试浏览的当前结构如下:
主窗口->面板->窗口
我在C#中使用以下方法
public Boolean wasUserLoggedIn(string id1, string id2)
{
Thread.Sleep(500);
var mdiClient = window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndAutomationId(id1));
Thread.Sleep(500);
var selectPatient = (Window)mdiClient.Get(SearchCriteria.ByControlType(ControlType.Window).AndAutomationId(id2));
Thread.Sleep(500);
return selectPatient != null? true: false;
}
并按如下所示调用方法:
Boolean wasFound = wasUserLoggedIn("40960", "40961");
用于标识ControlType和AutomationID的UIspy对象:
AutomationId: 40960
ControlType: ControlType.Pane
Name:
HelpText:
Bounding rectangle: 8,78,900,581
ClassName: MDIClient
IsOffScreen: False
FrameworkId: Win32
ProcessId: 5964
AutomationId: 40961
ControlType: ControlType.Window
Name: Home
HelpText:
Bounding rectangle: 8,59,900,600
ClassName: ClaWin01000000H_2
IsOffScreen: False
FrameworkId: Win32
ProcessId: 5964
我建议升级到TestStack.White
而不是旧的White库。
问题是您不应该使用.Get()
来解析窗口。 对于MDI应用程序,应使用MdiChild()
,如果它是modal
窗口,则在parent
窗口上使用.ModalWindow()
或返回到应用程序,然后使用Window()
获取窗口。
希望能有所帮助
Pane
是Window
AutomationElement
的后代吗? 您尝试查找的Window
可能没有对准焦点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.