Skip to content

Need to get selection from disabled ComboBox #674

@jeffhuckins

Description

@jeffhuckins

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

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions