main
1from playwright.sync_api import sync_playwright
2import os
3
4# Example: Automating interaction with static HTML files using file:// URLs
5
6html_file_path = os.path.abspath('path/to/your/file.html')
7file_url = f'file://{html_file_path}'
8
9with sync_playwright() as p:
10 browser = p.chromium.launch(headless=True)
11 page = browser.new_page(viewport={'width': 1920, 'height': 1080})
12
13 # Navigate to local HTML file
14 page.goto(file_url)
15
16 # Take screenshot
17 page.screenshot(path='/mnt/user-data/outputs/static_page.png', full_page=True)
18
19 # Interact with elements
20 page.click('text=Click Me')
21 page.fill('#name', 'John Doe')
22 page.fill('#email', 'john@example.com')
23
24 # Submit form
25 page.click('button[type="submit"]')
26 page.wait_for_timeout(500)
27
28 # Take final screenshot
29 page.screenshot(path='/mnt/user-data/outputs/after_submit.png', full_page=True)
30
31 browser.close()
32
33print("Static HTML automation completed!")