Basic Concepts

Browser Automation Basics

GoTo vs Get

GoTo and Get both launch or reuse a real browser and navigate it to a URL. The page renders, scripts run, and GetPageSource returns the rendered DOM either way. GoTo uses a headful, visible Chrome window. Get runs headless. On Windows, headless means the workflow does not require a visible desktop -- the machine can be locked, or someone can continue working on it without the browser interfering. GoTo is the right choice when the workflow needs a visible, interactive browser.

// GoTo - headful, visible Chrome

GPAL.Browser

.GoTo("https://example.com")

.WithSelector("h1")

.GetGrid(out var heading);


// Get - headless

GPAL.Browser

.Get("https://api.example.com/data")

.GetPageSource(out string html);

NOTE

Close() ends the session. Close(true) also forces the browser process to exit if it does not shut down on its own, removes any temporary profile directory that was in use, and for Selenium terminates the driver process. OttoMagic and Puppeteer need no additional cleanup.

Tabs and History

NewTab opens a new browser tab at the given URL and NextTab switches the tab GPAL is currently automating. Useful when a workflow opens several result pages and needs to process each in turn. Back and Forward step through the active tab's navigation history, the same as clicking a browser's back and forward buttons.

GPAL.Browser

.GoTo("https://example.com")

.NewTab("https://example.com/reports")

.NextTab;


// History navigation

GPAL.Browser

.GoTo("https://example.com")

.GoTo("https://example.com/page2")

.Back

.Forward;

Checking the Server's Response Code

ServerResponseCode holds the HTTP status code from the most recent GoTo or Get, available no matter which automation engine you are using. 0 means GPAL could not determine a status, -1 means an error occurred while checking. For Puppeteer this comes straight from the Chrome DevTools Protocol. For OttoMagic it comes from the StatusCode on the RESTClient class that GPAL.OttoMagicClient wraps. For Selenium, which has no built-in way to read response codes, GPAL reads the browser performance logs to extract it, so the value is available there too without any extra setup.

browser.GoTo("https://example.com/maybe-missing-page");


if (404 == browser.ServerResponseCode)

{

GPAL.PublishSimpleEvent(GPALEventType.WARN, "Page not found, skipping");

}

else if (200 == browser.ServerResponseCode)

{

// proceed with the workflow

}

WARNING

GPAL extracts the Selenium response code from the browser's performance logs, which depend on the driver and browser version exposing them. If the logs aren't available, ServerResponseCode falls back to 0 (undetermined) rather than failing the workflow.

💬 Ask GPAL