FlaUI / FlaUInspect

Inspect tool to inspect UIs from an automation perspective
MIT License
410 stars 97 forks source link

AutomationId property displays the name of the item if there is no AutomationId set #4

Closed HyruleWarrior closed 6 years ago

HyruleWarrior commented 6 years ago

I am seeing some odd behavior with FlaUInspect. I have an element I am trying to find, it has a name of "listView" but there is no AutomationId set for it. When I look at this item in FlaUInspect, it says the AutomationId is "listView" and the name property is blank. If I set an AutomationId for the element, the correct AutomationId shows up, but name looks like it is still blank. The element is using x:Name to set the name.

I am not sure if this actually impacts grabbing the element with FlaUI. I specified an AutomationId of "listView" and I got back an element, but it was a different element and I didn't dig into it to see exactly which element was being returned and if that element did in fact have "listView" as it's AutomationId.

Roemer commented 6 years ago

The x:Name is something only related to XAML and has nothing to do with UIA. The Name property in UIA is usually the "Content" or "Text" of an element. As a listview itself does not have any text, it makes sense to be empty. Also the automationid is something that is sometimes set by microsoft itself to a value they think makes sense. The specific code from Microsoft for a listview is:

protected override string GetAutomationIdCore()
{
    string text = base.GetAutomationIdCore();
    if (string.IsNullOrEmpty(text))
    {
        FrameworkElement frameworkElement = (FrameworkElement)base.Owner;
        text = base.Owner.Uid;
        if (string.IsNullOrEmpty(text))
        {
            text = frameworkElement.Name;
        }
    }
    return text ?? string.Empty;
}
HyruleWarrior commented 6 years ago

Oh interesting. Thanks for the info!

HyruleWarrior commented 6 years ago

One other thing I noted but forgot to say is that when inspecting these with another tool like "Snoop", they show up without an AutomationId. So it seems like it might not be related to how the Microsoft code for ListView is (since I would expect other UI inspection tools to report the AutomationId the same) and it might be a difference in how FlaUInspect is reporting it. I reopened the issue for now.

Roemer commented 6 years ago

Snoop and WPFInspector and such tools analyze the application from WPF side and not from UIA side. So they they show completely different information. I have an issue in FlaUI to add support for that information (see https://github.com/Roemer/FlaUI/issues/28).

HyruleWarrior commented 6 years ago

Ok, thank you.