question

Markus-8039 avatar image
0 Votes"
Markus-8039 asked Markus-8039 commented

How to Casting to autoelement(button) when selecting an item in the listbox? UI Automation

First of all, when the program is turned on, processes appear, and among the processes, I select the process that I want to control (in this case, I get a handle value from the process).
Find all button controls in the lower part and add them to the listbox.
I want to use the invoke method or the focus method for the buttons added in order, but when I click an item in the listbox, a NullReference error occurs. What is the problem?
Also, how should i solve it?

Items added to the listbox are simply
Dim isExpandCollapsePatternAvailableProperty As Condition = New PropertyCondition(AutomationElement.IsExpandCollapsePatternAvailableProperty, True)
Dim isenablecondi As Condition = New PropertyCondition(AutomationElement.IsEnabledProperty, True)
Dim isoffcondi As Condition = New PropertyCondition(AutomationElement.IsOffscreenProperty, True)
Dim andcon As AndCondition = New AndCondition(isoffcondi, isenablecondi, isExpandCollapsePatternAvailableProperty)
Dim aec As AutomationElementCollection = GetMainControl.FindAll(TreeScope.Subtree, isenablecondi)
For Each ae As AutomationElement In aec
If ae.Current.ControlType.ProgrammaticName = "ControlType.Button" Then
ListBox1.Items.Add(ae.Current.ControlType.LocalizedControlType & ":" & ae.Current.Name)
End If
Next

It is added in this way and the use was done through TryCast. How can I actually control the buttons through the list of buttons added to the listbox?
Sorry my English, Google translator.


Example Usage: Dim AE As AutomationElement = TryCast(ListBox1.SelectedItem, AutomationElement)
ButtonInvoker(AE)


Also, it seems that the third-party program to be manipulated was developed in WPF.

windows-wpf
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you know what line of code is throwing the null reference exception and what object on the line is null that means the object is not in memory it's null valued it don't exist?

0 Votes 0 ·

Yes

         ListBox2.Items.Clear()
         Dim ListB As AutomationElement = TryCast(ListBox1.SelectedItem, AutomationElement)
         Dim isenablecondi As Condition = New PropertyCondition(AutomationElement.IsEnabledProperty, True)
         @HERE@ Dim aec As AutomationElementCollection = ListB.FindAll(TreeScope.Subtree, isenablecondi)
         For Each ae As AutomationElement In aec
             If ae.Current.ControlType.ProgrammaticName = "ControlType.ListItem" Then
                 ListBox2.Items.Add(ae.Current.ControlType.LocalizedControlType & ":" & ae.Current.Name)
             End If
         Next
0 Votes 0 ·

0 Answers