Paste a Playwright or Selenium script. The same parse → translate → generate pipeline as the CLI rewrites CSS/XPath call sites into an AgentQL query_elements script — instantly, in the browser.
"""
Auto-generated AgentQL migration of sample_legacy.py.
Regenerate with ``python generator.py`` — do not hand-edit locators here.
Requires AGENTQL_API_KEY (see .env.example).
"""
import agentql
from playwright.sync_api import sync_playwright
QUERY = """
{
user_input
icon_eye_button
pwd_input
btn_primary_button
}
"""
def run_migrated_flow() -> None:
"""Run the migrated flow with semantic AgentQL selectors."""
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=True)
page = agentql.wrap(browser.new_page())
page.goto('https://example.com/login')
elements = page.query_elements(QUERY)
elements.user_input.fill('demo_user')
elements.icon_eye_button.click()
elements.pwd_input.fill('s3cret!')
elements.btn_primary_button.click()
browser.close()
if __name__ == "__main__":
run_migrated_flow()
{
user_input
icon_eye_button
pwd_input
btn_primary_button
}| Line | Action | Kind | Brittle selector | AgentQL name |
|---|---|---|---|---|
| 19 | fill | css | div#app > div.container > form.login-form > input[name='user'] | user_input |
| 24 | click | css | div > ul.toolbar > li:nth-child(2) > button.icon-eye | icon_eye_button |
| 27 | fill | css | form[action='/auth/login'] input[type='password'][data-testid='pwd'] | pwd_input |
| 32 | click | xpath | //div[@id='footer']//button[contains(@class, 'btn-primary')] | btn_primary_button |
This demo runs the CLI's heuristic translator in the browser (the same names you get from python migrator.py --fallback). The Python CLI can also call gpt-4o-mini when OPENAI_API_KEY is set. Generated scripts need AGENTQL_API_KEY at runtime.