import sys
sys.stdout.reconfigure(encoding='utf-8')
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://localhost:9222')
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()
    
    # Check current URL
    print('Current URL:', page.url)
    
    # List all buttons/clickable elements in the header and intro area
    buttons = page.locator("div[role='button'], button, a[role='button']")
    print('Total buttons:', buttons.count())
    for i in range(min(buttons.count(), 30)):
        btn = buttons.nth(i)
        txt = btn.inner_text().strip().replace('\n', ' ')
        aria = btn.get_attribute('aria-label') or ''
        if txt or aria:
            print(f"[{i}] text='{txt}' | aria='{aria}'")
            
    # Also look for any element with 'Edit' or 'Add'
    edits = page.locator("text=/Edit|Add/i")
    print('Total elements with Edit/Add:', edits.count())
    for i in range(min(edits.count(), 20)):
        el = edits.nth(i)
        tag = el.evaluate("e => e.tagName")
        txt = el.inner_text().strip().replace('\n', ' ')
        print(f"Edit/Add [{i}] tag={tag} text='{txt}'")
