Tutorials

Tutorials

Automating a Login Flow with a Native Menu Selection

A common real-world pattern: before you can log in, you have to pick an option from a dropdown menu (like choosing which portal to log into), then fill in a username and password. This tutorial walks through clicking a native menu, selecting an option, filling in credentials, and using StealthLeftClick on the final submit button.

Complete Program

The workflow opens the site, clicks a menu to reveal portal options, picks one, then waits for the login form to appear before filling in a username and password and clicking the final submit button.

using GenerallyPositive;

using GenerallyPositive.Browser;

using static GenerallyPositive.Enums;

GPAL

.WithPublishToConsole(GPALEventType.All & ~GPALEventType.DEEPDEBUG)

.WithPublishToDebug();

IBrowser browser = GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithUseStealth(StealthType.GoogleReferrer)

.WithLoadImages(true)

.ToGPALObject();

browser.GoTo("https://www.example-bank.com/");

Selector loginMenuSelector = GPAL.Selector.WithCSS("span.login-select-toggle").WithSelectorName("Login Menu").ToGPALObject();

Selector cashManagerOptionSelector = GPAL.Selector.WithCSS("#login-select > option:nth-child(3)").WithSelectorName("Cash Manager Option").ToGPALObject();

Selector usernameSelector = GPAL.Selector.WithCSS("input[name='txtUsername']").WithSelectorName("Username").ToGPALObject();

Selector passwordSelector = GPAL.Selector.WithCSS("#txtPassword").WithSelectorName("Password").ToGPALObject();

Selector loginButtonSelector = GPAL.Selector.WithValue("LOG IN").WithSelectorName("Login Button").ToGPALObject();

Selector finalLoginButtonSelector = GPAL.Selector.WithCSS("#btnLogin").WithSelectorName("Final Login Button").ToGPALObject();

browser

.WaitFor(5_000)

.LeftClick(loginMenuSelector);

browser

.LeftClick(cashManagerOptionSelector);

// some automation engines select the entry but leave the menu open, which can interfere with the username field

browser

.WaitFor(5_000)

.LeftClick(loginMenuSelector);

browser

.WithSelector(usernameSelector)

.FillInFrom("SampleUser");

browser

.LeftClick(loginButtonSelector)

.WaitFor(1_000);

browser

.WithSelector(passwordSelector)

.FillInFrom("SamplePassword123!")

.StealthLeftClick(finalLoginButtonSelector)

.WaitFor(5_000);

browser.Close(true);

Stealth Mode for Sites That Watch for Bots

WithUseStealth(StealthType.GoogleReferrer) sets a Chrome DevTools Protocol leak handler and makes the browser look like it arrived via a Google search rather than a fresh automated session. WithLoadImages(true) keeps image loading on so the page's signature looks like a normal browser, not a stripped-down automation profile.

IBrowser browser = GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithUseStealth(StealthType.GoogleReferrer)

.WithLoadImages(true)

.ToGPALObject();

TIP

Banking and financial sites often run bot-detection scripts that check referrer headers, image loading, and CDP fingerprints. WithUseStealth and WithLoadImages(true) help the automated browser blend in with normal traffic.

Open the Menu, Then Pick the Option

This site's login portal selector is a two-step interaction: clicking the menu toggle reveals the option list, then clicking the desired option (here, a native select option located by nth-child) makes the selection. The workflow clicks the menu toggle again afterward because some automation engines leave the menu visually open after selecting, which can block the username field underneath.

Selector loginMenuSelector = GPAL.Selector.WithCSS("span.login-select-toggle").WithSelectorName("Login Menu").ToGPALObject();

Selector cashManagerOptionSelector = GPAL.Selector.WithCSS("#login-select > option:nth-child(3)").WithSelectorName("Cash Manager Option").ToGPALObject();

browser

.WaitFor(5_000)

.LeftClick(loginMenuSelector);

browser

.LeftClick(cashManagerOptionSelector);

// some automation engines select the entry but leave the menu open

browser

.WaitFor(5_000)

.LeftClick(loginMenuSelector);

WARNING

Different automation engines can handle the same dropdown differently - one might close the menu after selecting an option, another might not. If a workflow that fills in a field right after a menu selection intermittently fails, try clicking the menu toggle again first to confirm it's closed.

Fill In the Username and Submit the First Step

WithSelector plus FillInFrom types the username into the field. The first login button click moves to the password step, with a short WaitFor afterward to let the next field render.

browser

.WithSelector(usernameSelector)

.FillInFrom("SampleUser");

browser

.LeftClick(loginButtonSelector)

.WaitFor(1_000);

Fill In the Password and Submit with StealthLeftClick

StealthLeftClick performs the click using the same stealth-aware interaction as the rest of the session, which matters for the final submit button on sites that scrutinize login attempts. The WaitFor(5_000) afterward gives the page time to process the login before the workflow continues.

browser

.WithSelector(passwordSelector)

.FillInFrom("SamplePassword123!")

.StealthLeftClick(finalLoginButtonSelector)

.WaitFor(5_000);

browser.Close(true);