static_html_automation.py 953 B

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