简体   繁体   English

使用已编码的ui testmethod获取Silverlight列表项

[英]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.

相关问题 运行循环遍历多个页面的已编码UI TestMethod - Running Coded UI TestMethod that loops through multiple pages 当其中包含的文本在运行时未知时,在编码的UI中选择一个选中的列表框项目控件 - Selecting a checked list box item control in coded UI when the text contained within will not be known at runtime 使用 Resharper/NUnit 运行 Coded UI 测试将找不到 Silverlight 组件 - Running Coded UI tests with Resharper/NUnit will not locate Silverlight components 在编码用户界面中,如何获取属性并对其进行正确声明? - In Coded UI, how to get a property and assert with it properly? C#编码的UI测试永远不会在网格中选择正确的项目 - C# Coded UI Test never selects correct item in grid 为Silverlight 5应用程序添加Coded UI支持时为什么无法加载System.Core? - Why System.Core fails to load when adding Coded UI support for Silverlight 5 application? 从具有相同项目的列表中选择时,编码的UI感到困惑 - Coded UI confused when selecting from list with identical items C#-如何从Execute UI中的ExecuteScript填充列表 - C# - How to Populate a List from ExecuteScript in Coded UI 在Silverlight上的列表中找不到项目的索引 - Can't find index of an Item on a List on Silverlight 具有列表项属性的Silverlight TreeMap绑定文本 - Silverlight TreeMap Binding Text with Property of a list item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM