Branchwell

Skillfarm / skills · skillfarm.ai / converted / webapp-testing / examples / static_html_automation.py

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