Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Test and interact with local web applications using native Python Playwright scripts
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/element_discovery.py
1from playwright.sync_api import sync_playwright23# Example: Discovering buttons and other elements on a page45with sync_playwright() as p:6browser = p.chromium.launch(headless=True)7page = browser.new_page()89# Navigate to page and wait for it to fully load10page.goto('http://localhost:5173')11page.wait_for_load_state('networkidle')1213# Discover all buttons on the page14buttons = page.locator('button').all()15print(f"Found {len(buttons)} buttons:")16for i, button in enumerate(buttons):17text = button.inner_text() if button.is_visible() else "[hidden]"18print(f" [{i}] {text}")1920# Discover links21links = page.locator('a[href]').all()22print(f"\nFound {len(links)} links:")23for link in links[:5]: # Show first 524text = link.inner_text().strip()25href = link.get_attribute('href')26print(f" - {text} -> {href}")2728# Discover input fields29inputs = page.locator('input, textarea, select').all()30print(f"\nFound {len(inputs)} input fields:")31for input_elem in inputs:32name = input_elem.get_attribute('name') or input_elem.get_attribute('id') or "[unnamed]"33input_type = input_elem.get_attribute('type') or 'text'34print(f" - {name} ({input_type})")3536# Take screenshot for visual reference37page.screenshot(path='/tmp/page_discovery.png', full_page=True)38print("\nScreenshot saved to /tmp/page_discovery.png")3940browser.close()