Frames, Shadow DOM & Scoping

Switch To Shadow Root

Switches the context into the matched element's shadow root, so following selectors are evaluated within that shadow tree rather than the light DOM around it. Implemented at every layer: IBrowser, RESTClient, MagicHelper, PuppeteerClient, and PuppeteerCommunicator. Mandatory parameter: elementId.

NOTE

This reaches an open shadow root. A closed root has nothing to switch into: OttoMagic on its own gets the host element instead, while Selenium and Puppeteer can still reach the real element.

Examples

GPAL Fluent: High-level fluent C# API

IGPALGrid<string> results = GPAL.Grid.ToGPALObject();


browser

.InShadowDom(shadowHostSelector)

.WithSelector(shadowChildSelector)

.GetGrid(ref results);


browser.InMainDom();

MagicHelper: MagicHelper utility library

//MagicHelper.InShadowDom is an alias for the same call.

browser.MagicHelper.SwitchToShadowRoot("#shadow-host");

Puppeteer Client: Puppeteer-style C# client

browser.PuppeteerClient.SwitchToShadowRoot("#shadow-host").Execute();

Puppeteer Communicator: Low-level communicator

//Named SwitchToShadowDom here, taking the host's selector. The layers above call the same thing SwitchToShadowRoot, and GPAL calls it InShadowDom.

await browser.PuppeteerCommunicator.SwitchToShadowDom(string shadowHostSelector);

REST Client: Direct REST/HTTP client

//SwitchToShadowRoot is the only name for this on the REST client.

browser.OttoMagicClient.SwitchToShadowRoot("#shadow-host").Execute();

💬 Ask GPAL