Equivalent code generation using FlaUI.UIA3 for accessing DevExpress DataGrid rows & columns in WPF

1.1k views Asked by At

I am using FlaUI to automate my WPF app. I have a datagrid control from DevExpress. I want to access any individual row and all the columns of that row and edit it using FlaUI. The DevExpress forum has the following sample available but this is for UIA library.How can I rewrite this using FlaUI libraries?

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);

Very new to FlaUI & automation.

1

There are 1 answers

0
Apoorv On BEST ANSWER

Finally with some help from DevExpress Support, I was able to achieve my intentions. Here is the piece of code that works well :)

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;
        }

before this, finding element using FlaUI is necessary

Grid(reference from FlaUI.Core.AutomationElements) private Grid grid=>windows.FindFirstDescendant(cf=>cf.ByAutomationID("dataGrid").AsGrid();