CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008

    Exclamation UI Automation AutomationIdProperty Not Working

    Hey all i have the following code that *should* find a button and click on it within the program:
            aeDesktop = AutomationElement.RootElement
            Dim numwaits As Integer = 0
              Debug.WriteLine("Looking for CDBurnerXP . . . ")
              aeProgram = aeDesktop.FindFirst(TreeScope.Children, New PropertyCondition(AutomationElement.NameProperty, "CDBurnerXP"))
              numwaits += 1
              Loop While aeProgram Is Nothing AndAlso numwaits < 50
              If aeProgram Is Nothing Then
                  Throw New Exception("Failed to find CDBurnerXP")
                  Debug.WriteLine("Found the CDBurnerXP Application!")
              End If
              Dim btnID As String = "000F0206"
              Dim btnDecimalID As String = Convert.ToInt32("000F0206", 16).ToString
              aeBtn = aeProgram.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.AutomationIdProperty, btnDecimalID))
              Dim ipClickBtn As InvokePattern = DirectCast(aeBtn.GetCurrentPattern(InvokePattern.Pattern), InvokePattern)
        Catch ex As Exception
              Debug.WriteLine("Fatal error: " & ex.Message)
        End Try
    When i run it this is my output:
        Looking for CDBurnerXP . . . 
        A first chance exception of type 'System.InvalidCastException' occurred in UIAutomationClientsideProviders.dll
        A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in UIAutomationClient.dll
        Found the CDBurnerXP Application!
        A first chance exception of type 'System.NullReferenceException' occurred in windowsAutomation.exe
        Fatal error: Object reference not set to an instance of an object.
        The program '[11036] windowsAutomation.vshost.exe: Program Trace' has exited with code 0 (0x0).
        The program '[11036] windowsAutomation.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
    It seems to find the program box just fine but once it gets to the aeBtn=nothing and i am trying to find out why!

    I know i have the correct Control id since the example HERE works just fine with the MS Calculator.

    Any help would be great to solve this problem!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: UI Automation AutomationIdProperty Not Working

    Have you stepped through the code in a debugger to find out what's going wrong?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.