Skip to content

feat(sdk-python): add role and text locator builders - #3192

Open
supremeboxlogos wants to merge 7 commits into
amel/role-text-locators-tsfrom
amel/role-text-locators-python
Open

supremeboxlogos wants to merge 7 commits into
amel/role-text-locators-tsfrom
amel/role-text-locators-python

Conversation

@supremeboxlogos

Copy link
Copy Markdown
Member

why

Add Python role/text builders in a focused language-specific review. Stacked on #3191; approximately 580 changed lines including documentation and tests.

what changed

  • Add lazy get_by_role/get_by_text on Page and Locator, descendant Locator.locator, and public role enum/literal types.
  • Reuse generated query/option models, preserve earlier nth selections and explicit false filters, and serialize supported Python regex flags for browser evaluation.
  • Document Python usability, matching options, and chaining. No extension runtime, generated-model, or other language API changes here.

test plan

  • 803 Python tests passed; 1 skipped.
  • Python typecheck, Ruff lint/format, and generator freshness passed.
  • 27 reference checks and 15 structural SDK parity checks passed.
  • Nine headful Chrome assertions previously passed against this same Python implementation, covering regex filters, literal selector delimiters, indexed scoping, and an existing click action.
  • Independent strict structural review passed; no new smoke-test infrastructure.

@supremeboxlogos
supremeboxlogos requested a review from a team as a code owner October 15, 2026 06:46
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5843ace

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@browserbasehq/stagehand-python Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 8 files

Architecture diagram
sequenceDiagram
    participant Py as Python SDK User
    participant Page as Page
    participant Loc as Locator
    participant SL as semantic_locator.py
    participant RPC as RPCClient
    participant Browser as Browser Engine

    Note over Py,Browser: Lazy Locator Building Flow

    Py->>Page: get_by_role(role, name=..., exact=...)
    Page->>SL: encode_step(role_step(...))
    SL->>SL: Build GetByRoleOptions + QueryStep
    SL-->>Page: Encoded selector string
    Page->>Loc: new Locator(encoded selector)

    Py->>Loc: get_by_text(text, exact=...)
    Loc->>SL: _append(text_step(...))
    SL->>SL: Decode parent selector into steps
    alt Parent has nth index
        SL->>SL: Append nth step to query
    end
    SL->>SL: Serialize semantic locator query
    SL-->>Loc: New lazy Locator

    Note over Py,Browser: Action Execution (e.g., click)

    Py->>Loc: click(timeout=...)
    Loc->>RPC: locator.click(page_id, selector, nth, options)
    RPC->>Browser: Evaluate query in browser
    Browser-->>RPC: Click result
    RPC-->>Loc: LocatorClickResult
    Loc-->>Py: Result

    Note over Py,SL: Regex Pattern Handling

    alt Pattern with IGNORECASE/MULTILINE/DOTALL
        SL->>SL: Convert to JS flags (i/m/s)
    else Unsupported flags (ASCII, VERBOSE, DEBUG)
        SL-->>Py: Raise ValueError
    end

    Note over Py,Loc: Descendant Chaining

    Py->>Loc: locator("span")
    Loc->>SL: _append(selector_step("span"))
    SL->>SL: Preserve parent steps + nth
    SL-->>Loc: New chained lazy Locator
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/docs/v4/reference/locator.mdx Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant