0

I'm having trouble using C# UIAutomation to find UI elements of Firefox.

In Inspect.exe, everything looks fine:

inspect.exe

However, when using the method below on the window as root, only the elements highlighted yellow are found. I need to get to the blue element but have not been able to get it. The solution below is based on this post:

UIAutomation won't retrieve children of an element

public static void WalkControlElements(AutomationElement rootElement)
    {
        if (rootElement == null) return;

        var children = new List<AutomationElement>();

        var currentChild = TreeWalker.RawViewWalker.GetFirstChild(rootElement);

        while (currentChild != null)
        {
            children.Add(currentChild);
            currentChild = TreeWalker.RawViewWalker.GetNextSibling(currentChild);
        }

        foreach (var child in children)
        {
            Console.WriteLine(child.ToString());
            WalkControlElements(child);
        }
    }
Community
  • 1
  • 1
Marc
  • 12,706
  • 7
  • 61
  • 97

1 Answers1

0

Because they are not window to get handle of them. They are elements of their root window. You must get handle of the elements(or items).

Behdad
  • 1,459
  • 3
  • 24
  • 36
  • Ok, and how can I do this? – Marc Dec 11 '15 at 17:02
  • I did not use UIAutomation for my any projects. I use "FindWindowEx" , "FindWindow", "FindWindowByIndex" and "SendMessage" Methods for Automation in C#. For example: Intptr WindowHandler = FindWindow("WindowsForms10.Window.8.app.0.33c0d9d", "FOREXTrader PRO - LIVE"); And after his I use FindWindowEx(WindowHandler,Intpr,Zero,QRibbonCaption1"); and then I get username field by FindWindowByIndex and Send "WM_SETTEXT" message type with value of Username that I want to it. – Behdad Dec 11 '15 at 17:18
  • Search about FindWindow in C# and get handle and hooking to other applications in C# – Behdad Dec 11 '15 at 17:23
  • And notice that for automation in browsers like Firefox, its better to use extention(plugin). By JavaScript you can get the nodes you want and change their value very easy. And you can communicate from you plugin to you C# App by Socket Programming or another methods like reading and writing file. – Behdad Dec 11 '15 at 17:25