3

I'm using "AddAutomationFocusChangedEventHandler" to capture when an input field in IE is focused on. When the AutomationElement is passed back, the AutomationId is always empty.

When I view the field in Inspect.exe, it shows the HTML input fields id value as the AutomationId. I'm not sure why UI Automation is not returning this value back to me. My application and IE are running under the same User.

Is there a problem inherent to UI Automation?

        Automation.AddAutomationFocusChangedEventHandler(OnFocusChangedHandler);


        private void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args)
        {
            Console.WriteLine("Focus changed!");

            AutomationElement element = null;

            try
            {
                element = src as AutomationElement;
            }
            catch { }

            if (element != null)
            {                    
                    string name = element.Current.Name;
                    string id2 = element.Current.AutomationId;

                    int processId = element.Current.ProcessId;

                    InsertTextUsingUIAutomation(element, id2);

                    using (Process process = Process.GetProcessById(processId))
                    {
                        Console.WriteLine("  Name: {0}, Id: {1}, Process: {2}", name, id2, process.ProcessName);
                    }
                }
            }
        }

0 Answers0