【发布时间】:2014-12-23 06:31:59
【问题描述】:
我已经四处搜索,但尚未找到我的问题的答案。简而言之,我正在关注this UI 自动化介绍指南,并尝试实现类似的设计以在我的程序中自动化 UI 测试。
在不影响背景的情况下,基本上正在发生的事情是没有设置我设置的 Grid 中的 UI 元素,因此触发了 if-else 语句的 == null 部分。所以下面是一个尝试设置登录按钮的例子,但是文本框和其他按钮等其他元素也存在同样的问题。
//Get LogIn Button
AutomationElement aeLogInButton = null;
aeLogInButton = aeP.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "LoginButton"));
//Tell user if LogIn button was received
Console.WriteLine("Before if Statement");
if(aeLogInButton == null)
{
throw new Exception("No Login Button!");
}
else
{
Console.WriteLine("Login Button Found");
}
Console.WriteLine("After if-else");
出于合规目的,我不得不缩短窗口名称,但我向您保证它是准确写的。此外,XAML 文件中登录按钮的 x:Name 是“LoginButton”,因此 NameProperty 应该可以正常工作。我不知道为什么找不到这些 UI 元素。如果您能提供任何帮助或帮助,我将不胜感激。
【问题讨论】:
-
不要使用代码发布损坏的图像链接,只需将代码发布为文本。
-
您是否在数据/项目模板中搜索您的元素?
-
@Athari 我已经添加了代码块,对此感到抱歉。
-
@Fred 不,我不知道。它只是一个典型的 XAML 文件,为格式化添加了一个网格。
标签: c# wpf xaml user-interface automation