Misc

Iframes and Shadow DOM - Reaching Nested Elements

Switching Into an Iframe

InIframe(selector) switches the active browsing context into the matched iframe. All subsequent WithSelector calls resolve inside that frame until InMainDom() resets back to the top-level document. Nesting is supported -- call InIframe again from within an already-switched context to go one level deeper.

GPAL.Browser

.GoTo("https://page-with-iframe.com")

.InIframe(iframeSel)

.WithSelector(innerInput)

.FillInFrom("value")

.WithSelector(innerSubmitBtn)

.LeftClick()

.InMainDom()

.WithSelector(outerConfirm)

.LeftClick()

.Close();

NOTE

XPath selectors do not cross the shadow boundary. Inside a Shadow DOM context (InShadowDom), use only CSS selectors with WithSelector.

Shadow DOM

InShadowDom(selector) pierces the shadow root of the matched host element and makes it the active search context. Elements inside the shadow tree are then reachable with CSS selectors via WithSelector. Call InMainDom() to return to the top-level document when done.

GPAL.Browser

.GoTo("https://page-with-web-components.com")

.InShadowDom(hostComponentSel)

.WithSelector(".inner-button")

.LeftClick()

.InMainDom()

.Close();

InElement for Scoped Searches

InElement(selector) scopes all subsequent WithSelector searches to the subtree of the matched element. Unlike InIframe and InShadowDom it does not switch the browsing context -- it just constrains searches to that element's children. This is useful for scraping a specific table, panel, or section without matching identical selectors elsewhere on the page.

GPAL.Browser

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

.InElement(tableSel)

.WithSelector("tr")

.WithAllThatMatch()

.GetGrid(out var rows)

.InMainDom()

.Close();

NOTE

If a page has multiple similar structures (multiple tables, multiple forms), InElement pins your selectors to the right one without having to write more specific CSS paths.

💬 Ask GPAL