0

I added reference to UIAutomationTypes and to UIAutomationClient and use those imports

    Imports System.Windows.Automation
    Imports System.Runtime.InteropServices
    Imports System.Text

But I get an error: type "AutomationElement" is not defined when I use that code

 Dim rootElement As AutomationElement = AutomationElement.FromHandle(hwnd)

what is wrong?

  • This https://stackoverflow.com/questions/1469386/referencing-system-windows-automation may help if it is a problem from the Imports – mcutrin Jun 29 '21 at 09:17
  • https://stackoverflow.com/questions/31737003/how-can-i-include-automationelement-in-c-sharp-what-do-i-have-to-add. please refer this solutions. – senthilkumar2185 Jun 29 '21 at 09:54
  • I get an error when I add "using System.Windows.Automation.AutomationElement" AutomationElement is not a member of System.Windows.Automation – user4889347 Jun 29 '21 at 10:33

2 Answers2

0

OK I had to add reference "UIAutomationClient" from files and not to choose from reference manager

0

After setting a reference to

  • UIAutomationClient
  • UIAutomationCore
  • UIAutomationCoreRes

all in uiautomationcore.dll you can do things like this in vb .net

Imports System

Module Program

    Sub Main(args As String())
        Dim uiA As UIAutomationClient.CUIAutomation8 = New UIAutomationClient.CUIAutomation8
        Dim root As UIAutomationClient.IUIAutomationElement

        root = uiA.GetRootElement()

        Console.WriteLine("Hello World!" + root.CurrentClassName)
    End Sub
End Module

to be complete example in c#

    using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            UIAutomationClient.CUIAutomation8 uia = new UIAutomationClient.CUIAutomation8();
            UIAutomationClient.IUIAutomationElement root;

            root = uia.GetRootElement();

            Console.WriteLine("Hello World!" + root.CurrentClassName);
        }
    }
}
junkew
  • 116
  • 5