Tutorials

Tutorials

Automating YouTube Studio: Navigating a Multi-Step Upload Dialog

YouTube Studio's video upload dialog is a multi-step wizard - details, monetization, visibility, and more - each step reached by clicking a tab and then interacting with that step's controls. This tutorial shows the selector-and-click pattern for moving through a wizard like this, plus attaching to a browser that's already running on a debug port.

Complete Program

This is a trimmed version of the actual test program. It attaches to a Chrome instance already running with a remote debugging port open, defines selectors for two tabs in the upload wizard plus a playlist picker, and clicks through: open the details tab, open the playlist dropdown, pick the first playlist, confirm, then move to the monetization tab.

using GenerallyPositive;

using GenerallyPositive.Browser;

using static GenerallyPositive.Enums;

GPAL.WithTypingDelay(50);

Selector detailsTab = (Selector)GPAL.Selector

.WithCSS("#step-badge-0");

Selector playlistDropdown = (Selector)GPAL.Selector

.WithCSS("ytcp-video-metadata-playlists ytcp-dropdown-trigger");

Selector firstPlaylistOption = (Selector)GPAL.Selector

.WithCSS("#checkbox-label-0");

Selector doneButton = (Selector)GPAL.Selector

.WithCSS("ytcp-playlist-dialog .done-button");

Selector monetizationTab = (Selector)GPAL.Selector

.WithCSS("#step-badge-1");

IBrowser browser = (Browser)GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithExistingBrowser(6969)

.WithSelector(detailsTab).LeftClick()

.WithSelector(playlistDropdown).LeftClick()

.WithSelector(firstPlaylistOption).LeftClick()

.WithSelector(doneButton).LeftClick()

.WithSelector(monetizationTab).LeftClick();

Attaching to an Already-Running Browser

WithExistingBrowser(6969) tells GPAL to connect to a Chrome instance that was launched separately with --remote-debugging-port=6969, instead of starting a new browser. This is useful when a human (or another process) already has the upload dialog open and you want automation to take over from there.

IBrowser browser = (Browser)GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithExistingBrowser(6969)

TIP

Everything after WithExistingBrowser uses the same WithSelector/LeftClick pattern as a freshly launched browser - the only difference is how the browser connection was established.

Each Wizard Step Is a CSS Selector and a Click

The upload dialog's step tabs use predictable IDs like #step-badge-0 for Details and #step-badge-1 for Monetization. WithSelector sets the active target and LeftClick fires on it - chaining several of these together walks the wizard one step at a time.

Selector detailsTab = (Selector)GPAL.Selector

.WithCSS("#step-badge-0");

Selector monetizationTab = (Selector)GPAL.Selector

.WithCSS("#step-badge-1");

browser

.WithSelector(detailsTab).LeftClick()

// ... other steps ...

.WithSelector(monetizationTab).LeftClick();

A Sub-Dialog Is Just More Selectors and Clicks

Opening the playlist dropdown reveals a sub-dialog with its own checkbox list and Done button. There's no special handling needed - it's the same WithSelector/LeftClick pattern, just targeting elements that only exist once the dropdown is open.

Selector playlistDropdown = (Selector)GPAL.Selector

.WithCSS("ytcp-video-metadata-playlists ytcp-dropdown-trigger");

Selector firstPlaylistOption = (Selector)GPAL.Selector

.WithCSS("#checkbox-label-0");

Selector doneButton = (Selector)GPAL.Selector

.WithCSS("ytcp-playlist-dialog .done-button");

browser

.WithSelector(playlistDropdown).LeftClick()

.WithSelector(firstPlaylistOption).LeftClick()

.WithSelector(doneButton).LeftClick();

WARNING

IDs like #checkbox-label-0 refer to the first item in a generated list - if the playlist order changes, #checkbox-label-0 picks a different playlist. The real test program also keeps an XPath fallback for selectors like this, since YouTube Studio's generated markup shifts between releases.

The Whole Sequence Is One Chain

Because every LeftClick returns the same browser object, the entire wizard walk - details tab, playlist dropdown, pick a playlist, confirm, monetization tab - reads as a single fluent statement. Each WithSelector call simply re-targets the chain for the next click.

browser

.WithSelector(detailsTab).LeftClick()

.WithSelector(playlistDropdown).LeftClick()

.WithSelector(firstPlaylistOption).LeftClick()

.WithSelector(doneButton).LeftClick()

.WithSelector(monetizationTab).LeftClick();