Frames, Shadow DOM & Scoping

Switch To Element

Sets the matched element as the search root, so following selectors are evaluated relative to it rather than against the whole document. The GPAL-level call is InElement, and InMainDom puts the root back. Mandatory parameter: elementId.

NOTE

InElement and InFrame are the same operation underneath. An iframe is an element, and scoping to it is scoping to what is inside it.

Examples

GPAL Fluent: High-level fluent C# API

browser

.InElement(containerSelector)

.WithSelector(childSelector)

.LeftClick();


browser.InMainDom();

MagicHelper: MagicHelper utility library

//MagicHelper has no SwitchToElement method; use browser.MagicHelper.InElement("#container") instead.

browser.MagicHelper.InElement("#container");

Puppeteer Client: Puppeteer-style C# client

browser.PuppeteerClient.SwitchToElement("#container").Execute();

Puppeteer Communicator: Low-level communicator

//Holds the element as the root that later selectors resolve against. Nothing goes over the wire beyond finding it, because CDP has no current element: the scope is GPAL's to keep, and it is dropped when the frame changes or the context is put back.

await browser.PuppeteerCommunicator.SwitchToElement(string elementSelector);

REST Client: Direct REST/HTTP client

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

browser.OttoMagicClient.SwitchToElement("#container").Execute();

💬 Ask GPAL