我正在使用怀特构建一个自动化测试套件。我需要做的一件事是单击System Promoted Notification区域(开始栏的右下角)中的图标。不过,我很难把它辨认给怀特。使用Spy++,我发现它嵌套在三层深的窗口中,没有要搜索的标题,这是怀特识别窗口的正常方式。因此,我正在尝试按类查找正确的窗口。
根据Spy++的说法,我首先需要获取window 10042,它的类是"Shell_TrayWnd“。然后,它的子窗口10048具有类TrayNotifyWnd,最后系统升级具有类ToolbarWindow32的通知区域,窗口1005E。从this answer中得到一些提示,我尝试了以下代码:
win=Desktop.Instance.Get<Window>(SearchCriteria.ByNativeProperty(AutomationElement.ClassNameProperty, "Shell_TrayWnd"));但是当我尝试运行它时,我得到了这个错误记录(原文如此):
Exception: Error occured while geting (),AutomationElementIdentifiers.ClassNameProperty=Shell_TrayWnd
有什么想法吗?
编辑:我更改了错误日志记录,以便获得完整的回溯,而不仅仅是异常消息,并找到了System.ArgumentException: Must specify at least two conditions.
因此,我将代码修改为
win = Desktop.Instance.Get<Window>(SearchCriteria.ByClassName("Shell_TrayWnd").AndIndex(0));但是,尽管我指定了两个条件,它仍然给出了完全相同的错误消息。
Exception: TestStack.White.WhiteException: Error occured while geting (),ClassName=Shell_TrayWnd,Index=0 ---> System.ArgumentException: Must specify at least two conditions.
发布于 2017-11-11 02:32:34
在白色UI自动化中,SearchCriteria和SearchConditions是有区别的。SearchConditions由框架在内部使用,而criteria作为参数在外部添加,然后在内部转换为条件(然后进一步转换为微软UIAutomation框架)。
如果将搜索条件更改为
SearchCriteria.ByClassName("Shell_TrayWn").NotIdentifiedByText(String.Empty)它将停止抛出错误。
这是因为它默认通过名称/文本作为搜索条件来搜索所有内容,并且抛出了一条不相关的错误消息(它应该是一个消息为“必须指定名称/文本条件”的ArgumentException )。
https://stackoverflow.com/questions/44903655
复制相似问题