使用UI Automation选择一行数据网格 [英] Select a row of datagrid using UI Automation

查看:97
本文介绍了使用UI Automation选择一行数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编写UI自动化软件。我需要在datagrid中选择一行,然后单击运行按钮。我尝试了互联网上的大多数示例代码,但它们对我不起作用。例如,选择gridview行:



当我编写以下代码时:

Hi,
I'm writing a UI automation software. I need to select a row in the datagrid and then click on the run button. I tried most of the example codes in the internet and they didn't work for me. For example for selecting a gridview row:

When I write the following code:

AutomationElement dataGrid = this.mainWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "2885"));

if (dataGrid != null) {

GridPattern pattern = GetGridPattern(dataGrid);
AutomationElement tempElement = pattern.GetItem(1, 1);
tempElement.SetFocus();
}







我收到错误:目标元素无法获得焦点。这与最后一行有关。



我也尝试过代码:




I receive the error: "Target element cannot receive focus." which is related to the last line.

I also tried the code:

AutomationElement mainGrid = // find the grid in the window var columnCount = (int)mainGrid.GetCurrentPropertyValue(GridPattern.ColumnCountProperty);

var mainGridPattern = (GridPattern)mainGrid.GetCurrentPattern(GridPattern.Pattern);

var rowToSelect = 2;

// select just the first cell var item = mainGridPattern.GetItem(rowToSelect, 0);

var itemPattern = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern);

itemPattern.Select();





但我和我收到错误:不支持的模式。



我应该提一下,我正在使用UI Spy来检索元素属性。



你能不能解释我出了什么问题,我应该如何选择一行?



but I and I received the error :"Unsupported Pattern".

I should mention that I'm using UI Spy for retrieving the elements properties.

Could you explain me what's wrong and how should I select a row?

推荐答案

过了一会儿,但看看这个就是



Been a while, but check this out

Quote:

GridPattern不支持对网格的主动操作;此功能需要TransformPattern控件模式。

GridPattern does not support active manipulation of a grid; the TransformPattern control pattern is required for this functionality.





http://msdn.microsoft.com/en-us/library/system.windows.automation.gridpattern.aspx [ ^ ]


这篇关于使用UI Automation选择一行数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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