Skip to main content

Function: iterateMatchingChildren()

iterateMatchingChildren<ItemT>(host, container, childSelector, driverClass, groupSelector?): AsyncGenerator<ItemT>

Defined in: packages/core/src/drivers/childListHelper.ts:42

Yield a driver for each descendant of container that matches childSelector, addressed positionally by :nth-child.

:nth-child is the only element-position pseudo that both jsdom and Playwright resolve identically, and — unlike the :nth-of-type used by getListItemByIndex and friends — it counts across element types. This matters for lists whose items either mix tags (e.g. <a>/<div> menu items) or are interspersed with non-items (a role="separator", an overflow trigger) sharing a tag with the items: each position is filtered through childSelector, so non-matching siblings are skipped without throwing off the index.

When groupSelector is supplied, a child that is not itself an item but matches groupSelector is treated as a wrapper and recursed into — so items nested one (or more) levels deep are still found. Pass a specific selector (e.g. a role="group" section) to descend only through those wrappers, or '*' to descend through any layout container. Omit it for a flat (direct-children-only) walk.

Iteration walks positions until no child exists there, using only Interactor.exists — portable across interactors (notably, getAttribute(..., true) is NOT a reliable element count: Playwright drops null entries, jsdom keeps them). container must resolve to a single element so :nth-child is unambiguous.

Type Parameters​

ItemT​

ItemT extends ComponentDriver<{ }>

Parameters​

host​

ComponentDriver

container​

PartLocator

childSelector​

string

driverClass​

ComponentDriverCtor<ItemT>

groupSelector?​

string

Returns​

AsyncGenerator<ItemT>