Hi I am using this code to read datagridview cell.Its working fine till
var myString = targetText.Cached.Name;
targettext is null
Code:
LogMessage("Getting RootElement...");
AutomationElement rootElement = AutomationElement.RootElement;
if (rootElement != null)
{
LogMessage("OK." + Environment.NewLine);
Automation.Condition condition = new PropertyCondition(AutomationElement.NameProperty, "Form1");
LogMessage("Searching for Test Window...");
AutomationElement appElement = rootElement.FindFirst(TreeScope.Children, condition);
if (appElement != null)
{
LogMessage("OK " + Environment.NewLine);
LogMessage("Searching for Gridview control...");
AutomationElement txtElementA = GetTextElement(appElement, "dg");
var rows = txtElementA.FindAll(TreeScope.Children, PropertyCondition.TrueCondition);
foreach (AutomationElement loginLine in rows)
{
var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
for (var i = 0; i < loginLinesDetails.Count; i++)
{
var cacheRequest = new CacheRequest
{
AutomationElementMode = AutomationElementMode.None,
TreeFilter = System.Windows.Automation.Automation.RawViewCondition
};
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.AutomationIdProperty);
cacheRequest.Push();
var targetText = loginLinesDetails[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"));// targettext is null
cacheRequest.Pop();
var myString = targetText.Cached.Name;//Object reference not set ///to instance of an object error
}
}
}
else
{
WriteLogError();
}
}
Here is an image of an example form i am trying to read at present.If it works for this small app it will definately work for big apps.
All I want to do is read the cells of a datagridview.I dont know whether I am doing right or not can any one please help me with this. There would be great appreciation if someone could help me