TestStack / White

DEPRECATED - no longer actively maintained
Other
1.02k stars 486 forks source link

Need to get selection from disabled ComboBox #674

Open jeffhuckins opened 1 year ago

jeffhuckins commented 1 year ago

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

`