2014-10-27 92 views
-1

找遍四周,还没有找到我的问题的答案。总之,我下面this入门指南UI自动化和想实现一个类似的设计在我的程序自动化UI测试。访问WPF UI元素在网格

背景的出路,基本上所发生的事情是在电网无UI元素我已经设置了被设定,从而引发if-else语句的==空区域。下面是一个尝试设置登录按钮的例子,但是其他元素(如文本框和其他按钮)也存在同样的问题。

//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"); 

为了达标目的,我不得不缩短窗口名称,但我向你保证它是准确写入的。此外,X:在XAML文件中的登录按钮的名称是“LoginButton”所以NameProperty应该是工作。我对为什么没有找到这些UI元素感到茫然。我将不胜感激您提供的任何帮助或帮助。

+2

相反张贴损坏的链接与代码映像,只是职位的代码为文本。 – Athari 2014-10-27 23:19:36

+0

你在数据/项目模板里搜索你的元素吗? – Fred 2014-10-27 23:38:03

+0

@Athari我已经添加了代码块,对此很抱歉。 – dak1220 2014-10-28 11:49:39

回答

0

改变TreeScope.Children到TreeScope.Descendants完美。感谢大家的帮助。