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{
51 public class ElementAssistant : IAllowElementSettingsAndActions
52 {
53 private ElementSettings ElementSettings;// { get; set; }
54
59 internal ElementAssistant()
60 {
61 ElementSettings = new ElementSettings();
62 }
68 {
69 get
70 {
71 ElementSettings.InteractionType = InteractionType.JavaScript;
72 return this;
73 }
74 }
75
80 {
81 get
82 {
83 ElementSettings.InteractionType = InteractionType.Hardware;
84 return this;
85 }
86 }
87
93 {
94 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.LeftClick, ModifierKeys.NONE);
95 BrowserHelper.CheckDocumentReady(ElementSettings.Browser);
96
97 return this;
98 }
99
104 public IAllowElementSettingsAndActions LeftClick(Enums.ModifierKeys modifierKeys)
105 {
106 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.LeftClick, modifierKeys);
107 BrowserHelper.CheckDocumentReady(ElementSettings.Browser);
108
109 return this;
110 }
111
118 {
119 ElementSettings.WebElement = (GPALElement)webElement;
120 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.LeftClick, ModifierKeys.NONE);
121 BrowserHelper.CheckDocumentReady(ElementSettings.Browser);
122
123 return this;
124 }
125
133 {
134 ElementSettings.WebElement = (GPALElement)webElement;
135 Browser.LeftClickAndDownload(downloadTo, (GPALElement)webElement, ElementSettings.Selector);
136 BrowserHelper.CheckDocumentReady(ElementSettings.Browser);
137
138 return this;
139 }
140
146 {
147
148 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.LeftDoubleClick, ModifierKeys.NONE);
149
150 return this;
151 }
152
157 {
158 ElementSettings.WebElement = (GPALElement)webElement;
159 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.LeftDoubleClick, ModifierKeys.NONE);
160
161 return this;
162 }
163
169 {
170 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.MiddleClick, ModifierKeys.NONE);
171 BrowserHelper.CheckDocumentReady(ElementSettings.Browser);
172
173 return this;
174 }
175
180 {
181 GPALElement webElementToUse = (GPALElement)webElement ?? ElementSettings.WebElement;
182
183 ElementHelper.Click(ElementSettings.Browser, ElementSettings.Selector, ElementSettings.WebElement, ClickType.RightClick, ModifierKeys.NONE);
184
185 Thread.Sleep(250);
186 return this;
187 }
188
194 internal void ForSelector(Selector selector)
195 {
196 ElementSettings.Selector = selector;
197 }
204 {
205 ElementSettings.WebElement = (GPALElement)GPALElement;
206 return this;
207 }
208
214 {
215 ElementHelper.FillInFrom(ElementSettings.Browser, inputText, WriteMode.Overwrite, ElementSettings.WebElement);
216 //if (true == Browser.BrowserSettings.UseHeadless)
217 // ElementSettings.WebElement.SendKeys(inputText);
218 //else if (InteractionType.JavaScript == ElementSettings.InteractionType)
219 // ElementHelper.JavaScriptFillInFrom(ElementSettings.Browser, ElementSettings.WebElement, inputText, WriteMode.Overwrite);
220 //else if (InteractionType.Hardware == ElementSettings.InteractionType)
221 // ElementHelper.HardwareFillInFrom(Browser, ElementSettings.WebElement, 5, 5, inputText, WriteMode.Overwrite); // KLUDGE: 5,5 is to click inside the control
222 //else
223 // ElementSettings.WebElement.SendKeys(inputText);
224
225 return this;
226 }
227
233 {
234 ElementHelper.FillInFrom(ElementSettings.Browser, inputText, WriteMode.Insert, ElementSettings.WebElement);
235
236 //if (true != Browser.BrowserSettings.UseHeadless)
237 //{
238 // ElementSettings.WebElement.SendKeys(Keys.Control + "A"); // select all text and overwrite
239 // ElementSettings.WebElement.SendKeys(inputText);
240 //}
241 //else if (InteractionType.JavaScript == ElementSettings.InteractionType)
242 // ElementHelper.JavaScriptFillInFrom(ElementSettings.Browser, ElementSettings.WebElement, inputText, WriteMode.Insert);
243 //else if (InteractionType.Hardware == ElementSettings.InteractionType)
244 // ElementHelper.HardwareFillInFrom(Browser, ElementSettings.WebElement, 5, 5, inputText, WriteMode.Insert); // KLUDGE: 5,5 is to click inside the control
245 //else
246 //{
247 // ElementSettings.WebElement.SendKeys(Keys.Control + "A"); // select all text and overwrite
248 // ElementSettings.WebElement.SendKeys(inputText);
249 //}
250 return this;
251 }
252
258 {
259 ElementHelper.FillInFrom(ElementSettings.Browser, inputText, WriteMode.Append, ElementSettings.WebElement);
260
261 //if (true == Browser.BrowserSettings.UseHeadless)
262 // ElementSettings.WebElement.SendKeys(inputText);
263 //else if (InteractionType.JavaScript == ElementSettings.InteractionType)
264 // ElementHelper.JavaScriptFillInFrom(ElementSettings.Browser, ElementSettings.WebElement, inputText, WriteMode.Append);
265 //else if (InteractionType.Hardware == ElementSettings.InteractionType)
266 // ElementHelper.HardwareFillInFrom(Browser, ElementSettings.WebElement, 5, 5, inputText, WriteMode.Append); // KLUDGE: 5,5 is to click inside the control
267 //else
268 // ElementSettings.WebElement.SendKeys(inputText);
269
270 return this;
271 }
272
280 {
281 ElementHelper.SendKey(Browser, keyCode);
282 return this;
283 }
284
290 {
291 ElementHelper.SendString(Browser, textToSend);
292 return this;
293 }
294
299 public IAllowElementSettingsAndActions PressModifierKey(ModifierKeys modifierKeys)
300 {
301 if (ModifierKeys.NONE != modifierKeys)
302 {
303 if (true == ElementSettings.Browser.UseOttoMagic)
304 ElementSettings.Browser.MagicHelper.PressModifierKey(modifierKeys);
305 else if (true == ElementSettings.Browser.UsePuppeteer)
306 ElementSettings.Browser.PuppeteerClient.PressModifierKey(modifierKeys);
307 else
308 HardwareHelper.PressModifierKey(modifierKeys);
309 }
310
311 return this;
312 }
313
318 public IAllowElementSettingsAndActions ReleaseModifierKey(ModifierKeys modifierKeys)
319 {
320 if (ModifierKeys.NONE != modifierKeys)
321 {
322 if (true == ElementSettings.Browser.UseOttoMagic)
323 ElementSettings.Browser.MagicHelper.ReleaseModifierKey(modifierKeys);
324 else if (true == ElementSettings.Browser.UsePuppeteer)
325 ElementSettings.Browser.PuppeteerClient.ReleaseModifierKey(modifierKeys);
326 else
327 HardwareHelper.ReleaseModifierKeys(modifierKeys);
328 }
329 return this;
330 }
331
338 {
339 ElementHelper.ScrollElement(Browser, scrollAmount, ScrollTypes.Horizontal);
340 return this;
341 }
342
349 {
350 ElementHelper.ScrollElement(Browser, scrollAmount, ScrollTypes.Vertical);
351 return this;
352 }
353
357 internal Browser Browser
358 {
359 get
360 {
361 return ElementSettings.Browser;
362 }
363
364 set
365 {
366 ElementSettings.Browser = value;
367 }
368 }
369
374 public ElementAssistant ToGPALObject()
375 {
376 return this;
377 }
378 }
379}
380
Browser object that contains the fluent methods to create your Browser workflow. Instatiated using G...
Definition Browser.cs:68
IAllowElementSettingsAndActions PressModifierKey(ModifierKeys modifierKeys)
Press a modifier key: Alt, Control, Shift.
IAllowElementSettingsAndActions WithElement(IGPALElement GPALElement)
Define the element to act upon.
IAllowElementSettingsAndActions ReleaseModifierKey(ModifierKeys modifierKeys)
Release a modifier key: Alt, Control, Shift.
IAllowElementSettingsAndActions MiddleClick()
Left click the webelement, optionally emulating pressing a modifier key at the same time.
IAllowElementSettingsAndActions ScrollHorizontalPixels(int scrollAmount)
Scroll the element horizontally by number of pixels. Negative numbers scroll left....
IAllowElementSettingsAndActions RightClick(IGPALElement webElement=null)
Right click the webelement.
IAllowElementSettingsAndActions AppendFrom(string inputText)
Appends text to the end of the input webelement defined with .WithElement.
IAllowElementSettingsAndActions WithJavaScript
Interact with the webelement using javascript.
IAllowElementSettingsAndActions InsertFrom(string inputText)
Insert text at the beginning of the input webelement defined with .WithElement.
IAllowElementSettingsAndActions LeftDoubleClick(IGPALElement webElement)
Left double click the webelement.
IAllowElementSettingsAndActions LeftClick(Enums.ModifierKeys modifierKeys)
Left click the webelement, optionally emulating pressing a modifier key at the same time.
IAllowElementSettingsAndActions FillInFrom(string inputText)
Fill In (Ovewrite) text of the input webelement defined with .WithElement.
IAllowElementSettingsAndActions SendKey(byte keyCode)
Emulate pressing a special key like Home, End, Page Down. Use GPAL.VK_ defined virual keycodes or se...
IAllowElementSettingsAndActions LeftClick()
Left click the webelement, optionally emulating pressing a modifier key at the same time.
IAllowElementSettingsAndActions ScrollVerticalPixels(int scrollAmount)
Scroll the element vertically by number of pixels. Negative numbers scroll up. JavaScript only.
ElementAssistant ToGPALObject()
Returns this ElementAssistant as itself.
IAllowElementSettingsAndActions LeftDoubleClick()
Left double click the webelement.
IAllowElementSettingsAndActions LeftClick(IGPALElement webElement)
Left click the webelement, optionally emulating pressing a modifier key at the same time.
IAllowElementSettingsAndActions WithHardware
Interact with the webelement using hardware emulation.
IAllowElementSettingsAndActions LeftClickAndDownload(IGPALElement webElement, GPALFile downloadTo)
Left click the webelement and download a file.
IAllowElementSettingsAndActions SendString(string textToSend)
Send the string using hardware emulation.
Pseudo element used in Applications and Browser workflows for image matching and unified automation....
dynamic WebElement
The wrapped Selenium IWebElement or internal dynamic element.
GPAL File object instantied with GPAL.File Used to load tokens into a GPALGrid [rows/columns].
Definition GPALFile.cs:36
GPAL Selector used to locate Application and Browser elements. Instantiated with GPAL....
Definition Selector.cs:56