Hey all i have the following code that *should* find a button and click on it within the program:
Code:
Try
aeDesktop = AutomationElement.RootElement
Dim numwaits As Integer = 0
Do
Debug.WriteLine("Looking for CDBurnerXP . . . ")
aeProgram = aeDesktop.FindFirst(TreeScope.Children, New PropertyCondition(AutomationElement.NameProperty, "CDBurnerXP"))
numwaits += 1
Thread.Sleep(100)
Loop While aeProgram Is Nothing AndAlso numwaits < 50
If aeProgram Is Nothing Then
Throw New Exception("Failed to find CDBurnerXP")
Else
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)
ipClickBtn.Invoke()
Catch ex As Exception
Debug.WriteLine("Fatal error: " & ex.Message)
End Try
When i run it this is my output:
Code:
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!