Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get the text for ComboBoxItem #604

Open
3s-ap opened this issue Dec 20, 2023 · 2 comments
Open

Unable to get the text for ComboBoxItem #604

3s-ap opened this issue Dec 20, 2023 · 2 comments

Comments

@3s-ap
Copy link

3s-ap commented Dec 20, 2023

Describe the bug
I'm getting an empty text for WPF ComboBoxItem when using e.g. SelectedItem.Text.
Select(string textToFind) also does not work properly.

The issue is in the Text property getter: for WPF it tries to get the first child and returns its name:

    public virtual string Text
    {
      get
      {
        if (this.FrameworkType == FrameworkType.Wpf)
        {
          AutomationElement firstChild = this.Automation.TreeWalkerFactory.GetRawViewWalker().GetFirstChild((AutomationElement) this);
          if (firstChild != null)
            return firstChild.Properties.Name.Value;
        }
        return this.FrameworkAutomationElement.Properties.Name.Value;
      }
    }

But the problem is that the "actual" text element is not the first child.
The same implementation is in the ListBoxItem.

To fix this, the getter might be changed to something like:

public virtual string Text
{
	get
	{
		var treeWalker = this.Automation.TreeWalkerFactory.GetRawViewWalker();
		var child = treeWalker.GetFirstChild(this);

		while (child != null)
		{
			if (child.ControlType == FlaUI.Core.Definitions.ControlType.Text)
				return child.Name;

			child = treeWalker.GetNextSibling(child);
		}

		return this.FrameworkAutomationElement.Properties.Name.Value;
	}
}
@tomczakmarcel
Copy link

Hi, could you please show how does this ComboBox look at UIInspect tool?

@3s-ap
Copy link
Author

3s-ap commented Mar 19, 2024

As you may see, "Image" goes first:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants