[英]Get silverlight list item with coded ui testmethod
I have a very simple silverligt page which contains this listbox 我有一个非常简单的Silverligt页面,其中包含此列表框
<ListBox ItemsSource="{Binding itemList}" x:Name="list">
<ListBox.ItemTemplate>
<DataTemplate x:Name="datatemplate" >
<Grid Name="grid" AutomationProperties.AutomationId="grid" >
<TextBlock Text="{Binding Txt}" AutomationProperties.AutomationId="{Binding Id}"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I want my Coded UI test to select one of this list item and click on it, but i don't know how to search for itemlists. 我希望我的编码UI测试选择该列表项之一并单击它,但是我不知道如何搜索项目列表。 I tried everything but i cannot figure out how to get it.
我尝试了一切,但我不知道如何获得它。
here is my simple testmethod 这是我的简单测试方法
public void ClickOnItem()
{
SilverlightList list = new SilverlightList(this.UISilverlightApplicatiWindow.UISilverlightApplicatiDocument.UISilverlightControlHoPane.UIItemCustom.UIMainPageMainPage.UIListList);
list.SearchProperties.Add(SilverlightList.PropertyNames.AutomationId, "list");
SilverlightListItem item = new SilverlightListItem(list);
item.SearchProperties.Add(SilverlightListItem.PropertyNames.AutomationId, "3");
Mouse.Click(item);
}
(where "3" is the third element in the list, ofc) (其中“ 3”是列表中的第三个元素,ofc)
what have i to search for? 我要寻找什么? do i need additional xaml tags?
我是否需要其他xaml标签?
I`m not really sure if this is what you want but: 我不确定这是否是您想要的,但是:
Once you have the Framework element you can access the items using the "Items" property itself. 一旦拥有Framework元素,就可以使用“ Items”属性本身访问这些项目。 Example
例
var item = list.Items[index]
or using Linq 或使用Linq
var item = list.Items.First(c => c.Id == 3);
Once you have the item you can select it with SelectedItem property as follow: 获得项目后,可以使用SelectedItem属性选择它,如下所示:
list.SelectedItem = item;
or depending on the case 或视情况而定
list.SelectedValue = item;
To fire the click event you can simply call it giving null parameters as 要触发click事件,您可以简单地调用它,将null参数设置为
list.OnMouseLeftButtonDown(null)
Which means you want to fire it with no parameters. 这意味着您要不使用任何参数将其触发。
Please refer to the following link as a source http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox%28VS.95%29.aspx 请参考以下链接作为源http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox%28VS.95%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.