Automation_Threads_EU / screenshot.py
FincH12's picture
Initial commit from local
9963647 verified
Raw History Blame Contribute Delete
1.07 kB
import time
import threading
import http.server
import socketserver
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Start local server
def serve():
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", 8090), Handler) as httpd:
httpd.serve_forever()
server_thread = threading.Thread(target=serve, daemon=True)
server_thread.start()
time.sleep(1) # wait for server to start
try:
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--window-size=1400,900')
driver = webdriver.Chrome(options=options)
driver.get('http://localhost:8090/dashboard.html')
time.sleep(3) # Wait for animations and fetch (fetch will fail but UI will render)
driver.save_screenshot('dashboard_preview.png')
driver.quit()
print('Screenshot saved as dashboard_preview.png')
except Exception as e:
print(f'Error taking screenshot: {e}')