Skip to main content

playwright-pom-agent

Generates Playwright Python Page Object Model classes from a live page, using an LLM to propose locators and a live verification loop to make sure every locator it writes is actually unique on the page before it's used.

Data sent to the LLM provider

Generation sends the page's accessibility tree (roles, visible text, structure) and a small test-id attribute inventory (tag + attribute value + a short text snippet) to your configured LLM provider (Anthropic or OpenAI). It does NOT read cookies, local/session storage, or form field values. If a page visibly displays sensitive info (names, account numbers, etc.), that text is included in what's sent - review before running against such pages. The CLI prints this notice on every run; it doesn't block execution.

Locator priority

  1. get_by_test_id() (data-testid, or a custom attribute via --test-id-attribute)
  2. get_by_role()
  3. get_by_label()
  4. get_by_placeholder()
  5. get_by_text()
  6. get_by_alt_text() / get_by_title()
  7. #id CSS selector
  8. [name="..."] CSS selector
  9. Generic CSS / XPath (last resort)

Every candidate is verified with .count() == 1 on the live page before being written to the generated file. Ambiguous or unresolved elements are retried (default: 3 attempts, via .filter(has_text=...) or parent scoping) before being emitted with an # UNVERIFIED comment rather than looping forever.

Dynamic UI state (modals, dropdowns, accordions)

Only the DOM present at inspection time is visible. This tool does not auto-crawl interactions. To document elements behind an interaction:

  • CLI: pass --setup-script path/to/setup.py, a file defining def setup(page): ... that runs after navigation and before inspection (e.g. click to open a modal).
  • Programmatic API: drive page into the desired state yourself before calling POMAgent.generate(page).

Generated files

Generated POM files start with an # AUTO-GENERATED ... DO NOT EDIT header. Re-running generation overwrites the file completely - put custom logic in a subclass, not in the generated file.

CLI

Set ANTHROPIC_API_KEY or OPENAI_API_KEY (matching --provider) before running - the CLI also accepts --api-key directly, but the env var is preferred since CLI arguments can leak via shell history and process listings.

export ANTHROPIC_API_KEY=sk-...
pom-agent generate --url https://example.com/login \
  --out example_login_page.py \
  --test-id-attribute data-pw \
  --provider anthropic

Programmatic

from playwright.sync_api import sync_playwright
from playwright_pom_agent import POMAgent

with sync_playwright() as p:
    page = p.chromium.launch().new_page()
    page.goto("https://example.com/login")

    agent = POMAgent(provider="anthropic")
    code = agent.generate(page, out_path="login_page.py")

Testing

uv pip install -e ".[dev]"
pytest tests/

tests/test_fixtures/ runs against local HTML fixtures in tests/fixtures/. tests/test_demo/test_demo_url.py is a reference suite that exercises the whole tool against a real site - https://demo.realworld.show/, a public "Conduit" demo app with no data-testids or <label>s anywhere, so it genuinely tests the role/placeholder fallback tiers instead of the tier-1 shortcut most fixtures hit. It covers locator resolution across the login, register, settings, and editor pages, plus full programmatic and CLI generation runs that actually log in with the generated code - those runs write their generated POM classes to tests/test_demo/pages/ (overwritten on each run) so you can open real, working, generated output rather than just reading assertions. Use it as a template for pointing this tool at your own app (swap BASE_URL/TEST_EMAIL/TEST_PASSWORD, or set the REALWORLD_* env vars it reads).

These tests are marked live and require internet access:

pytest tests/ -m "not live"   # skip the live/network tests
pytest tests/ -m live         # run only the live tests

One test in that file makes a real, billed LLM call and is opt-in only - it won't run just because ANTHROPIC_API_KEY/OPENAI_API_KEY happen to be set in your shell:

RUN_LIVE_LLM_TESTS=1 ANTHROPIC_API_KEY=sk-... pytest tests/test_demo/test_demo_url.py -k real_llm

Metadata

Release files for playwright-pom-agent 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for playwright-pom-agent 0.1.0
File Size Uploaded Provenance Actions
playwright_pom_agent-0.1.0.tar.gz 71.6 kB With provenance Details for playwright_pom_agent-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for playwright-pom-agent 0.1.0
File Interpreter ABI Platform Actions
playwright_pom_agent-0.1.0-py3-none-any.whl Python 3 none any Details for playwright_pom_agent-0.1.0-py3-none-any.whl

Total release size: 89.4 kB

Release files / playwright_pom_agent-0.1.0.tar.gz

Download URL playwright_pom_agent-0.1.0.tar.gz
Size 71.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b6e59c704961c20a163b12f6e604a9558cebc924a514325d2e9f88bfa03b3e21
BLAKE2b-256 checksum
How to use checksums
6b306be0fbe6af22a821e57f9cb01366d5c185141a14944a0bb4b3ce64b6b3a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release files / playwright_pom_agent-0.1.0-py3-none-any.whl

Download URL playwright_pom_agent-0.1.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5927e341e35e0dc18a187aee64e75ed87fa57f262e2eeb43416e7d0d76f68665
BLAKE2b-256 checksum
How to use checksums
b065a75d8421f042d1aba5d05f972e579f7b2a9f00e2b404628fcabeb7905d5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Security for playwright-pom-agent 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for playwright_pom_agent-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page