AI Agent News/stories/browserbase-s-stagehand-adds-getbytext-for-finding-elements-by-text.md

Browsers

Browserbase's Stagehand adds getByText() for finding elements by text

Stagehand's Python and TypeScript SDKs now include a getByText() method, released as a prerelease build. It lets developers locate page elements by their text, with options for exact matching and scoping.

Source: github.com/browserbase/stagehand/releases/tag/stagehand-python%404.5.0a0.dev1739

The stagehand-python 4.5.0a0.dev1739 prerelease adds getByText() to the TypeScript SDK and get_by_text() to the Python SDK, so code can find elements by their text. By default the query is a case-insensitive substring match, and the exact option switches it to a case-sensitive match on the full text. Both modes normalize whitespace and strip zero-width spaces and soft hyphens from the query and the element text.

Text from inline child elements is combined when matching, and button, submit and reset inputs contribute their values. Content inside script, style, head, template and noscript elements is ignored. A matching descendant is preferred over its ancestor, and both open and closed shadow roots are searched.

Results are lazy locators that support actions, further chaining, count(), first() and nth(). Queries inside iframes require an explicit chaining step. Existing text-based locator syntax keeps its previous behavior.

Why it matters if you build agents

Agents can target elements by visible text through a dedicated method instead of hand-written text selectors, which can make browser automation code easier to read.

Developers should check how exact and substring matching behave before relying on them, and note that iframe content needs an explicit chain step.

Because this is an alpha-style prerelease build, the API may change before a stable release.

Get stories like this every weekday

One short email with the day's agent tooling news.

Subscribe