GPAL - Generally Positive Automation Library
v1.0
GPAL The Fluent Automation LIbrary
Toggle main menu visibility
Loading...
Searching...
No Matches
GPALAutomationElement.cs
1
// =============================================================================
2
// GPAL - Generally Positive Automation Library
3
// Copyright © 2026 Software Decisions, Inc. All rights reserved.
4
//
5
// This file is part of GPAL.
6
// Licensed under the Business Source License 1.1
7
//
8
// Primary development, architecture, and vision by Michael B. Vederman,
9
// CEO of Software Decisions, Inc., Texas.
10
//
11
// Internal development maintained privately.
12
// Public releases appear on GitHub: https://github.com/SoftwareDecisionsInc/GPAL.
13
//
14
// See LICENSE for full terms, including Additional Use Grant.
15
// =============================================================================
16
17
//extern alias mUIA;
18
//extern alias mUIAtypes;
19
using
System;
20
using
System.Collections.Generic;
21
using
System.Linq;
22
using
System.Text;
23
using
System.Threading.Tasks;
24
using
System.Windows.Automation;
25
26
namespace
GenerallyPositive.Application
27
{
31
public
class
GPALAutomationElement :
IGPALAutomationElement
32
{
33
public
Application Application {
get
;
internal
set
; }
34
public
Selector Selector {
get
;
internal
set
; }
35
36
// public mUIA.System.Windows.Automation.AutomationElement Mae { get; set; }
40
public
AutomationElement
Ae
{
get
;
set
; }
47
public
IGPALElement
Gae
{
get
;
set
; }
53
internal
GPALAutomationElement
ImageMatch {
get
;
set
; }
63
public
bool
Selected
64
{
65
get
66
{
67
bool
retVal =
false
;
68
object
pattern;
69
70
if
(
null
!=
Ae
&&
true
==
Ae
.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern))
71
retVal = ((SelectionItemPattern)pattern).Current.IsSelected;
72
else
if
(
null
!=
Ae
&&
true
==
Ae
.TryGetCurrentPattern(TogglePattern.Pattern, out pattern))
73
retVal = ToggleState.On == ((TogglePattern)pattern).Current.ToggleState;
74
else
75
retVal = ContainerSaysSelected(
Ae
) ||
true
== MsaaHelper.Selected(Application,
Ae
);
76
77
return
retVal;
78
}
79
}
80
95
private
static
bool
ContainerSaysSelected(AutomationElement element)
96
{
97
bool
retVal =
false
;
98
AutomationElement above =
null
== element ? null : TreeWalker.ControlViewWalker.GetParent(element);
99
100
for
(
int
level = 0; level < ContainerLevels &&
false
== retVal &&
null
!= above; level++)
101
{
102
if
(
true
== above.TryGetCurrentPattern(SelectionPattern.Pattern, out
object
pattern))
103
foreach
(AutomationElement selected
in
((SelectionPattern)pattern).Current.GetSelection())
104
if
(
true
== element.Equals(selected))
105
retVal =
true
;
106
107
above = ControlType.Window == above.Current.ControlType ? null : TreeWalker.ControlViewWalker.GetParent(above);
108
}
109
110
return
retVal;
111
}
112
113
// how many parents up a selection container is looked for. The Explorer ribbon puts two elements
114
// between a tab and the element holding the tabs, and nothing legitimately sits further away than this
115
private
const
int
ContainerLevels = 5;
116
124
public
bool
?
Checked
125
{
126
get
127
{
128
bool
? retVal =
null
;
129
object
pattern;
130
131
if
(
null
!=
Ae
&&
true
==
Ae
.TryGetCurrentPattern(TogglePattern.Pattern, out pattern))
132
{
133
ToggleState state = ((TogglePattern)pattern).Current.ToggleState;
134
135
if
(ToggleState.On == state)
136
retVal =
true
;
137
else
if
(ToggleState.Off == state)
138
retVal =
false
;
139
}
140
141
return
retVal;
142
}
143
}
144
146
public
bool
Enabled
=>
null
!=
Ae
&&
true
==
Ae
.Current.IsEnabled;
147
153
public
bool
Displayed
=>
null
!=
Ae
&&
false
==
Ae
.Current.IsOffscreen;
154
160
public
string
Text
=>
null
==
Ae
? string.Empty : (
Ae
.GetText() ??
string
.Empty);
161
166
public
string
TagName
=>
null
==
Ae
167
? string.Empty
168
: (
Ae
.Current.ControlType?.ProgrammaticName ??
string
.Empty).Replace(
"ControlType."
,
""
);
169
171
public
string
Name
=>
null
==
Ae
? string.Empty : (Ae.Current.Name ??
string
.Empty);
172
177
public
System.Drawing.Point
Location
=>
null
==
Ae
178
?
new
System.Drawing.Point(0, 0)
179
:
new
System.Drawing.Point((
int
)
Ae
.Current.BoundingRectangle.Left, (
int
)
Ae
.Current.BoundingRectangle.Top);
180
182
public
System.Drawing.Size
Size
=>
null
==
Ae
183
?
new
System.Drawing.Size(0, 0)
184
:
new
System.Drawing.Size((
int
)
Ae
.Current.BoundingRectangle.Width, (
int
)
Ae
.Current.BoundingRectangle.Height);
185
190
internal
int
MenuCommand {
get
;
set
; } = 0;
194
internal
IntPtr MenuWindow {
get
;
set
; } = IntPtr.Zero;
195
internal
GPALAutomationElement()
196
{
197
198
}
199
internal
GPALAutomationElement(AutomationElement automationElement =
null
, IGPALElement gPALElement =
null
/*, mUIA.System.Windows.Automation.AutomationElement managedAutomationElement = null*/
)
200
{
201
Ae
= automationElement;
202
Gae
= gPALElement;
203
// Mae = managedAutomationElement;
204
}
205
}
206
}
207
GenerallyPositive.Application.GPALAutomationElement
Application workflow container for automation elements.
Definition
GPALAutomationElement.cs:32
GenerallyPositive.Application.GPALAutomationElement.Enabled
bool Enabled
Whether the element is enabled, from UIAutomation's IsEnabled.
Definition
GPALAutomationElement.cs:146
GenerallyPositive.Application.GPALAutomationElement.Text
string Text
The element's text, read through TextPattern where the control has one and ValuePattern otherwise,...
Definition
GPALAutomationElement.cs:160
GenerallyPositive.Application.GPALAutomationElement.Size
System.Drawing.Size Size
Dimensions of the element, from its bounding rectangle.
Definition
GPALAutomationElement.cs:182
GenerallyPositive.Application.GPALAutomationElement.Selected
bool Selected
Whether the element is selected, the same question GPALElement.Selected answers on a page....
Definition
GPALAutomationElement.cs:64
GenerallyPositive.Application.GPALAutomationElement.Displayed
bool Displayed
Whether the element is on screen, from UIAutomation's IsOffscreen. A control scrolled out of view or...
Definition
GPALAutomationElement.cs:153
GenerallyPositive.Application.GPALAutomationElement.Name
string Name
The element's name, which is how a window labels a control.
Definition
GPALAutomationElement.cs:171
GenerallyPositive.Application.GPALAutomationElement.Gae
IGPALElement Gae
GPAL psuedo element. Only the following properties are actually used: Location, Size,...
Definition
GPALAutomationElement.cs:47
GenerallyPositive.Application.GPALAutomationElement.Location
System.Drawing.Point Location
Screen coordinates of the element, the top left of its bounding rectangle. Always screen coordinates...
Definition
GPALAutomationElement.cs:177
GenerallyPositive.Application.GPALAutomationElement.TagName
string TagName
What kind of control this is, Button, ListItem, Edit and so on. A window's answer to a tag name,...
Definition
GPALAutomationElement.cs:166
GenerallyPositive.Application.GPALAutomationElement.Ae
AutomationElement Ae
UIAutomation element.
Definition
GPALAutomationElement.cs:40
GenerallyPositive.Application.GPALAutomationElement.Checked
bool? Checked
A checkbox's state, which has three of them: true ticked, false clear, and null for the third one,...
Definition
GPALAutomationElement.cs:125
GenerallyPositive.Application.IGPALAutomationElement
Definition
IGPALAutomationElement.cs:23
GenerallyPositive.IGPALElement
Definition
Interfaces.cs:1629
GenerallyPositive.Application
Definition
Application.cs:35
Application
GPALAutomationElement.cs
Generated by
1.17.0