Wpf控制搜索上下文问题 [英] Wpf Control search context issue

查看:57
本文介绍了Wpf控制搜索上下文问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


我遇到了使用&Ubsp; UITestControlFactoryUtility.FromAutomationId< T>(AppWindow,AutoId)方法按AutomationId属性搜索Wpf控件的问题。


这个想法如下:


我有多个行的WpfTable实例,其中每一行都是一个复杂的UI对象。所以我必须找到这一行中的一个字段。我使用    UITestControlFactoryUtility.FromAutomationId< T>(AppWindow,AutoId)方法搜索wpf控件
,并且在大多数情况下效果很好。下面是一个示例:


  T nControl = UITestControlFactoryUtility.FromAutomationId< T>(AppWindow,AutoId);


其中AppWindow是父控件用于搜索的(上下文)。


我获取表格的所有行:


UITestControlCollection aRows = dataTable.GetChildren();


//然后取每一行的所有字段:



foreach(aRows中的UITestControl aRow)


{


UITestControlCollection aFields = aRow.GetChildren();


//然后我想确保当前行不包含带有AutoId" lnkMoreValues"的wpf控件(HyperLink)。 in
//集合的第二个元素(aFields [1])


//所以我使用这个提到的方法:


WpfHyperLink  targetLnk = UITestControlFactoryUtility.FromAutomationId< WpfHyperLink>(aFields [1]," lnkMoreValues");


//期待获取当前行的null(我知道没有),但是此搜索在完全不同的行中找到此控件
//以某种方式忽略 搜索我设置的上下文


}


我在其他情况下此搜索正常工作。对于这种行为有什么解决方案吗?


提前致谢。


解决方案

对迟到的回复表示抱歉。希望你现在已经想到了这一点!如果没有,请尝试将Playback.PlaybackSetting.MatchExactHierarchy设置为true并再次运行您的方案。


谢谢,


~Tapas


Hello!

I faced a problem searching Wpf controls by AutomationId property using UITestControlFactoryUtility.FromAutomationId<T>(AppWindow, AutoId) method.

The idea is as follows:

I got WpfTable instance with a number of rows, where each row is a complex UI object. So I've got to find one of the fields in this row. I use  UITestControlFactoryUtility.FromAutomationId<T>(AppWindow, AutoId) method for searching wpf controls and it works well in most cases. Here is an example:

 T nControl = UITestControlFactoryUtility.FromAutomationId<T>(AppWindow, AutoId);

Where AppWindow is a parent control (context) for searching.

I take all rows of the table:

UITestControlCollection aRows = dataTable.GetChildren();

//And then take all the fields of each row:

foreach (UITestControl aRow in aRows)

{

UITestControlCollection aFields = aRow.GetChildren();

// And then I want to make sure that current row does not contain wpf control (HyperLink) with AutoId "lnkMoreValues" in //second element of collection (aFields[1])

// So I use this mentioned method:

WpfHyperLink targetLnk = UITestControlFactoryUtility.FromAutomationId<WpfHyperLink>(aFields[1], "lnkMoreValues");

//And expect to get null for current row (I know there is not), but this search finds this control in completely different row //somehow ignoring the search context I set

}

I other cases this search works correctly. Is there any kind of solution for this behavior?

Thanks in advance.

解决方案

Sorry about the late reply. Hope you have figured this out by now! If not, try setting the Playback.PlaybackSetting.MatchExactHierarchy to true and run your scenario again.

Thanks,

~ Tapas


这篇关于Wpf控制搜索上下文问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆