We use the code below to get a list of items from ComboBox in another application window. This code works (correctly receives the list of elements) for the ComboBox in any other application on which we tested this code, however, for this particular application, the distorted Name property obtained for each ListItem.
Here is the code:
using System.Windows.Automation;
var condition = new PropertyCondition(AutomationElement.NameProperty, "Change/Add/Delete Setting");
var condition2 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
var condition3 = new AndCondition(new Condition[] {condition, condition2});
var window = AutomationElement.RootElement.FindFirst(TreeScope.Subtree, condition3);
condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ComboBox);
var combo = window.FindFirst(TreeScope.Subtree, condition);
condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
AutomationElementCollection children = combo.FindAll(TreeScope.Subtree, condition);
var comboItems = new List<string>();
foreach (AutomationElement child in children)
{
comboItems.Add(child.Current.Name);
}
And here is a screenshot of what we get as a result for this application.

- What could lead to a distortion of the Name property as follows? Could this be a coding problem?
- How can we get the correct text for each element?
source
share