GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
ElementAssistant.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
17using OpenQA.Selenium;
18using System;
19using System.Collections.Generic;
20using System.Linq;
21using System.Text;
22using System.Threading;
23using System.Threading.Tasks;
24using static GenerallyPositive.Enums;
25
27{
53 public class ElementAssistant : IAllowForSelector, IAllowElementSettingsAndActions
54 {
58 private ElementSettings ElementSettings { get; set; }
59
64 internal ElementAssistant()
65 {
66 ElementSettings = new ElementSettings();
67 }
73 {
74 get
75 {
76 ElementSettings.InteractionType = InteractionType.Hardware;
77 return this;
78 }
79 }
80
85 {
86 if (InteractionType.Hardware == ElementSettings.InteractionType)
87 ElementHelper.HardwareClick(Application, ElementSettings.AutomationElement, ClickType.LeftClick, ModifierKeys.NONE);
88 else
89 ElementHelper.UIAutomationClick(Application, ElementSettings.Selector, ElementSettings.AutomationElement, ClickType.LeftClick, ModifierKeys.NONE);
90
91 Thread.Sleep(250);
92 return this;
93 }
94
99 public IAllowElementSettingsAndActions LeftClick(Enums.ModifierKeys modifierKeys)
100 {
101 if (InteractionType.Hardware == ElementSettings.InteractionType)
102 ElementHelper.HardwareClick(Application, ElementSettings.AutomationElement, ClickType.LeftClick, modifierKeys);
103 else
104 ElementHelper.UIAutomationClick(Application, ElementSettings.Selector, ElementSettings.AutomationElement, ClickType.LeftClick, modifierKeys);
105
106 Thread.Sleep(250);
107 return this;
108 }
109
114 {
115 if (InteractionType.Hardware == ElementSettings.InteractionType)
116 ElementHelper.HardwareClick(Application, ElementSettings.AutomationElement, ClickType.LeftDoubleClick, ModifierKeys.NONE);
117 else
118 {
119 ElementHelper.UIAutomationClick(Application, ElementSettings.Selector, ElementSettings.AutomationElement, ClickType.LeftDoubleClick, ModifierKeys.NONE);
120 }
121
122 Thread.Sleep(250);
123 return this;
124 }
125
130 {
131 if (InteractionType.Hardware == ElementSettings.InteractionType)
132 ElementHelper.HardwareClick(Application, ElementSettings.AutomationElement, ClickType.RightClick, ModifierKeys.NONE);
133 else
134 {
135 ElementHelper.UIAutomationClick(Application, ElementSettings.Selector, ElementSettings.AutomationElement, ClickType.RightClick, ModifierKeys.NONE);
136 }
137
138 Thread.Sleep(250);
139 return this;
140 }
141
146 public IAllowElementSettingsAndActions ScrollHorizontal(System.Windows.Automation.ScrollAmount scrollAmount)
147 {
148 ElementHelper.Scroll(Application, scrollAmount, ScrollTypes.Increments, ScrollTypes.Horizontal);
149 return this;
150 }
151
158 {
159 ElementHelper.Scroll(Application, percent, ScrollTypes.Percent, ScrollTypes.Horizontal);
160 return this;
161 }
162
168 public IAllowElementSettingsAndActions ScrollVertical(System.Windows.Automation.ScrollAmount scrollAmount)
169 {
170 ElementHelper.Scroll(Application, scrollAmount, ScrollTypes.Increments, ScrollTypes.Vertical);
171 return this;
172 }
173
180 {
181 ElementHelper.Scroll(Application, percent, ScrollTypes.Percent, ScrollTypes.Vertical);
182 return this;
183 }
184
191 {
192 ElementSettings.Selector = selector;
193 ElementSettings.InteractionType = selector.InteractionType;
194 return this;
195 }
196
201
203 {
204 ElementSettings.AutomationElement = (GPALAutomationElement)AutomationElement;
205 return this;
206 }
207
213 {
214 UnitOfWork.ElementNode elementNode = new UnitOfWork.ElementNode() { OffsetX = (int)(ElementSettings.Selector?.OffsetX ?? 5), OffsetY = (int)(ElementSettings.Selector?.OffsetY ?? 5), InteractionType = ElementSettings.InteractionType }; // if .ForSelector is not provided, default to 5
215 ElementHelper.FillInFrom(Application, ElementSettings.AutomationElement.Ae, elementNode, inputText, WriteMode.Overwrite);
216
217 return this;
218 }
219
225 {
226 ElementHelper.FillInFrom(Application, inputText, WriteMode.Insert);
227
228 return this;
229 }
230
236 {
237 UnitOfWork.ElementNode elementNode = new UnitOfWork.ElementNode() { OffsetX = (int)(ElementSettings.Selector?.OffsetX ?? 5), OffsetY = (int)(ElementSettings.Selector?.OffsetY ?? 5), InteractionType = ElementSettings.InteractionType }; // if .ForSelector is not provided, default to 5
238 ElementHelper.FillInFrom(Application, ElementSettings.AutomationElement.Ae, elementNode, inputText, WriteMode.Append);
239
240 return this;
241 }
242
250 {
251 HardwareHelper.SendKey(keyCode);
252 return this;
253 }
254
259 public IAllowElementSettingsAndActions PressModifierKey(ModifierKeys modifierKeys)
260 {
261 if (ModifierKeys.NONE != modifierKeys)
262 HardwareHelper.PressModifierKey(modifierKeys);
263 return this;
264 }
265
270 public IAllowElementSettingsAndActions ReleaseModifierKey(ModifierKeys modifierKeys)
271 {
272 if (ModifierKeys.NONE != modifierKeys)
273 HardwareHelper.ReleaseModifierKeys(modifierKeys);
274 return this;
275 }
276
279 internal Application Application
280 {
281 get
282 {
283 return ElementSettings.Application;
284 }
285
286 set
287 {
288 ElementSettings.Application = value;
289 }
290 }
291 }
292}
293
Application object that contains the fluent methods to create your Application workflow....
IAllowElementSettingsAndActions LeftDoubleClick()
Left double click the GPALAutomationElement.
IAllowElementSettingsAndActions ReleaseModifierKey(ModifierKeys modifierKeys)
Release a modifier key: Alt, Control, Shift.
IAllowElementSettingsAndActions AppendFrom(string inputText)
Appends text to the end of the input GPALAutomationElement defined with .WithElement.
IAllowElementSettingsAndActions LeftClick(Enums.ModifierKeys modifierKeys)
Left click the GPALAutomationElement, optionally emulating pressing a modifier key at the same time.
IAllowElementSettingsAndActions ScrolVerticalPercent(int percent)
Scroll the GPALAutomationElement vertically to the given percentage of its scrollable range.
IAllowElementSettingsAndActions ScrollHorizontal(System.Windows.Automation.ScrollAmount scrollAmount)
Scroll the GPALAutomationElement horizontally by an increment amount.
IAllowElementSettingsAndActions WithHardware
Interact with the GPALAutomationElement emulating hardware, not using UIAutomation;.
IAllowElementSettingsAndActions InsertFrom(string inputText)
Insert text at the beginning of the input GPALAutomationElement defined with .WithElement.
IAllowElementSettingsAndActions RightClick()
Right click the GPALAutomationElement.
IAllowElementSettingsAndActions WithElement(IGPALAutomationElement AutomationElement)
Define the GPALAutomationElement to act upon.
IAllowElementSettingsAndActions LeftClick()
Left click the GPALAutomationElement.
IAllowElementSettingsAndActions FillInFrom(string inputText)
Fill In (Ovewrite) text of the input GPALAutomationElement defined with .WithElement.
IAllowElementSettingsAndActions ScrollVertical(System.Windows.Automation.ScrollAmount scrollAmount)
Scroll the GPALAutomationElement vertically by an increment amount.
IAllowElementSettingsAndActions SendKeyCode(byte keyCode)
Emulate pressing a special key like Home, End, Page Down. Use GPAL.VK_ defined virual keycodes or se...
IAllowElementSettingsAndActions PressModifierKey(ModifierKeys modifierKeys)
Press a modifier key: Alt, Control, Shift.
IAllowElementSettingsAndActions ScrollHorizontalPercent(int percent)
Scroll the GPALAutomationElement horizontally to the given percentage of its scrollable range.
IAllowElementSetting ForSelector(Selector selector)
The selector associated with the webelement(s) you are acting upon. Used for the OffestX and OffsetY...
Application workflow container for automation elements.
GPAL Selector used to locate Application and Browser elements. Instantiated with GPAL....
Definition Selector.cs:56
InteractionType InteractionType
Defined method to interact with this element. NOTE: This can be overridden in the workflow.
Definition Selector.cs:731
Everything revolves around the Unit of Work. A Unit of Work is defined as one or more selectors betw...
Definition UnitOfWork.cs:39