0

我正在使用FlaUI自动化我的WPF应用程序。我有一个datagrid控制权DevExpress。我想访问任何单独的行和该行的所有列并使用FlaUI. DevExpress 论坛提供了以下示例,但这是针对UIA库的。如何使用库重写它FlaUI

AutomationElement gridElem = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "datagrid"));  
GridPattern gridPattern = (GridPattern)gridElem.GetCurrentPattern(GridPattern.Pattern);  
int rowCount = gridPattern.Current.RowCount;  
 List<object> values = new List<object>();  
 for (int i = 0; i < rowCount; i++) {  
    AutomationElement item = gridPattern.GetItem(i, 0);  
    ValuePattern valuePattern = (ValuePattern)item.GetCurrentPattern(ValuePattern.Pattern);  
    values.Add(valuePattern.Current.Value);

FlaUI对&非常陌生automation

4

1 回答 1

1

最后在DevExpress支持的帮助下,我能够实现我的意图。这是一段运行良好的代码:)

public void CreateNewViewGrid(Grid grid)
        {
            var pattern = grid.Patterns.Grid;
            var rowCount = pattern.Pattern.RowCount;
            var colCount = pattern.Pattern.ColumnCount;
            var values = new List<object>();

            List<string> columnNames = new List<string>();
            columnNames.Add("Vessel Id");
            columnNames.Add("Voyage Id");
            columnNames.Add("Load Date");
            columnNames.Add("Dis Date");
            columnNames.Add("Vessel Name");
            columnNames.Add("Status");

            for (int i = 0; i < rowCount; i++)
            {

                var item = pattern.Pattern.GetItem(i, 0);
                var item2 = pattern.Pattern.GetItem(i, 1);
                var value = (item2.Patterns.Value.Pattern.Value).ToString();
                values.Add((value));

                foreach (var data in columnNames)
                {
                    if (value == data)
                    {

                        var itemStatus = item.AsGridCell();

                        itemStatus.Click();

                    }
                }

            }

            //Console.WriteLine(string.Join(", ", values));
            //return values;
        }

在此之前,使用查找元素FlaUI is necessary

网格(参考自FlaUI.Core.AutomationElementsprivate Grid grid=>windows.FindFirstDescendant(cf=>cf.ByAutomationID("dataGrid").AsGrid();

于 2020-02-10T06:57:48.327 回答