A small GPALForm with a single button kicks off an Application automation chain: open an app, find an image-matched captcha checkbox, and click it with simulated mouse movement. Shows how a desktop form can act as a manual trigger for a GPAL workflow.
Here's the whole workflow, start to finish. Each piece is broken down and explained below.
using System;
using System.Windows.Forms;
using GenerallyPositive;
using GenerallyPositive.Application;
using GenerallyPositive.GPALForm;
using static GenerallyPositive.GPALForm.GPALForm;
static GPALLabel titleLabel = (GPALLabel)GPAL.Label
.WithText("Captcha Clicker");
static Selector captchaSelector = (Selector)GPAL.Selector
.WithSimulateMouse(true)
.WithImage(@"C:imagescaptcha.jpg")
.WithImageOffsetX(20)
.WithImageOffsetY(10);
static GPALButton startButton = (GPALButton)GPAL.Button
.WithName("Start")
.WithText("Start The Workflow")
.WithCallback<EventHandler>(StartClickHandler)
.WithShortcutKey(Keys.Alt | Keys.S);
static GPALButton exitButton = (GPALButton)GPAL.Button
.WithName("Exit")
.WithText("Exit")
.WithCallback<EventHandler>(ExitClickHandler)
.WithShortcutKey(Keys.Alt | Keys.E);
GPAL.WithExceptionHandler(ExceptionEventHandler)
.WithInformationHandler(ExceptionEventHandler);
GenerallyPositive.GPALForm.GPALForm myForm = (GenerallyPositive.GPALForm.GPALForm)GPAL.Form
.WithTitle("Captcha Clicker")
.WithLeft(1500)
.WithTop(100)
.WithFormControl(titleLabel)
.WithFormControl(startButton)
.WithFormControl(exitButton)
.ShowDialog();
static void StartClickHandler(object sender, EventArgs e)
{
GenerallyPositive.Application.Application application = (GenerallyPositive.Application.Application)GPAL.Application
.Open("explorer.exe")
.WithSelector(captchaSelector)
.WaitFor(1_000)
.LeftClick();
}
static void ExitClickHandler(object sender, EventArgs e)
{
((Form)((Button)sender).Parent.Parent).Hide();
}
The captcha checkbox isn't found by CSS or XPath - it's found by matching a saved screenshot. WithSimulateMouse(true) tells GPAL to move the cursor naturally to the matched location rather than dispatching a synthetic click event, which matters for captchas that watch for human-like input.
static Selector captchaSelector = (Selector)GPAL.Selector
.WithSimulateMouse(true)
.WithImage(@"C:imagescaptcha.jpg")
.WithImageOffsetX(20)
.WithImageOffsetY(10);
Simulated mouse movement and hardware-level clicks act on real screen coordinates. If the target window loses focus or moves between WaitFor and LeftClick, the click can land on the wrong element entirely.
GPAL.Form builds a small desktop window with a label and two buttons. WithCallback wires each button to a handler method, and WithShortcutKey gives each one an Alt-key accelerator. ShowDialog() blocks until the form closes, which is fine here since the form's only job is to wait for the user to press Start.
GenerallyPositive.GPALForm.GPALForm myForm = (GenerallyPositive.GPALForm.GPALForm)GPAL.Form
.WithTitle("Captcha Clicker")
.WithLeft(1500)
.WithTop(100)
.WithFormControl(titleLabel)
.WithFormControl(startButton)
.WithFormControl(exitButton)
.ShowDialog();
GPAL.Application.Open launches a desktop process by name. From there the chain looks just like a browser chain: WithSelector picks the target, WaitFor gives the app time to render, and LeftClick fires the click using whatever interaction mode the selector specifies (here, simulated mouse via the image selector).
static void StartClickHandler(object sender, EventArgs e)
{
GenerallyPositive.Application.Application application = (GenerallyPositive.Application.Application)GPAL.Application
.Open("explorer.exe")
.WithSelector(captchaSelector)
.WaitFor(1_000)
.LeftClick();
}
GPAL.Application uses the same Selector and chaining model as GPAL.Browser - WithSelector, WaitFor, LeftClick, and friends all behave the same way whether you're driving a browser tab or a desktop application window. See Desktop Application Automation.
The exit handler walks up from the clicked button to the owning Form and calls Hide() rather than Close(). This keeps the form (and its event handlers) alive in memory, which matters if other code still expects to interact with it later in the same process.
static void ExitClickHandler(object sender, EventArgs e)
{
((Form)((Button)sender).Parent.Parent).Hide();
}
Showing off some plain text in these paragraphs eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Here you can find different accents and emphasis sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
This is a link and how it could look like bestlinkinthebeautifulworld. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Here's just some classic bold text adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam notBoldSecondbestlinkinthebeautifulworld illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at adipisicing elit libero vel voluptas? Expedita, adipisicing facere dolores voluptatem ad ab rem assumenda soluta!
Other cuple of colors in case we want to emphasize several ways adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at voluptatem libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae quas consequuntur illo numquam assumenda autem exercitationem distinctio perspiciatis in natus. Eius dicta similique ipsam ipsa minima, nemo quae enim tempore.
GPAL
.CallIfNotFound(GenericCallIfNotFound)
.WithPublishToConsole();
//System.Drawing.Rectangle windowSize = new System.Drawing.Rectangle(10, 10, 1500, 1024);
// NOTE: we have to set browser = before we execute any steps
// this is due to the 'GenericCallIfNotFound' which might throw an exception, and BankScraper will not have the browser set when it calls scraper.Close()
// until the complete fluent line gets executed (meaning every step, meaning browser is not set until everything else succeeds)
browser = GPAL.Browser
.WithBrowserType(Enums.BrowserType.Chrome)
.WithProfileDataDirectory(ChromeProfileLocation)
.WithUseAutomationEngine(AutomationEngine.Selenium)
.WithWindowSize(new System.Drawing.Rectangle(0,0,1920,1080))
.ToGPALObject();