My WPF custom control has inner elements. In my case, my custom control is grid and inner elements are cells. You can find the AutomationPeer implementation in below,

public class GridAutomationPeer : FrameworkElementAutomationPeer, IGridProvider
{
      public virtual GridModel Model
        {
            get
            {
                var grid = this.Owner as GridBase;
                return grid.Model;
            }
        }
protected override AutomationControlType GetAutomationControlTypeCore()
        {
            return AutomationControlType.DataGrid;
        }

        protected override string GetClassNameCore()
        {
            return this.Owner.GetType().Name;
        }
protected override List<AutomationPeer> GetChildrenCore()
        {
            var peers = new List<AutomationPeer>();
            foreach (var kvp in this.cellPeers)
            {
                peers.Add(kvp.Value);
            }
            return peers;
        }
public override object GetPattern(PatternInterface patternInterface)
        {
            switch (patternInterface)
            {
                case PatternInterface.Grid:
                case PatternInterface.Selection:
                case PatternInterface.Table:
                    return this;

            return base.GetPattern(patternInterface);
        }
}
     int IGridProvider.ColumnCount
        {
            get
            {
                return this.Model.ColumnCount;
            }
        }

IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
        {
            if (row < this.Model.RowCount && column < this.Model.ColumnCount)
            {
                var cellPeer = this.GetOrCreateCellPeer(row, column);
                if (cellPeer != null)
                {
                    var item = this.ProviderFromPeer(cellPeer);
                    return item;
                }
            }
            return null;
        }
int IGridProvider.RowCount
        {
            get
            {
                return this.Model.RowCount;
            }
        }
}

My problem is that, it is properly recognized in Winium test script only if inspect.exe is opened. If the inspect.exe is not opened, Winium throws "Element not found" exception.

Below is my test script,


try
{
    var grid = driver.FindElementById("grid");
    var cell = grid.FindElement(By.Id("6,1"));
    if (cell.Text != "Movie Poster")
        Assert.Fail("Cell value is not Movie Poster");
    driver.Close();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message.ToString());
}

Exception details,

enter image description here

Please suggest me any solution for this.

0

There are 0 answers