I have a need to get the selection from a disabled WPF .NET 6 ComboBox in order to verify the selection even though it is disabled. I found a way for a WinForms .NET Framework ComboBox, but the solution doesn't work for a .NET 6 WPF ComboBox.
What worked for the WinForms .NET Framework ComboBox was:
` AutomationElement comboElement = window.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox).AndAutomationId(automationId));
if (comboElement != null)
{
LogEntry.Debug(log, $"Found ComboBox AutomationElement");
comboElement.TryGetCurrentPattern(ValuePattern.Pattern, out object oPattern);
if (oPattern != null)
{
text = (oPattern as ValuePattern).Current.Value;
LogEntry.Debug(log, $"Combo Selected Text = \"{text}\"");
}
else
{
LogEntry.Debug(log, "Failed to get ComboBox ValuePattern");
}
}
I have a need to get the selection from a disabled WPF .NET 6 ComboBox in order to verify the selection even though it is disabled. I found a way for a WinForms .NET Framework ComboBox, but the solution doesn't work for a .NET 6 WPF ComboBox.
What worked for the WinForms .NET Framework ComboBox was: ` AutomationElement comboElement = window.GetElement(SearchCriteria.ByControlType(ControlType.ComboBox).AndAutomationId(automationId));
`